package Server.Poker.TTZ;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;

import org.json.JSONObject;

import net.sf.json.*;
import redis.clients.jedis.Protocol.Command;
import redis.protocal.DbInfoMgr;
import redis.protocal.DwcRedisRecord;
import redis.protocal.UserRedisInfo;
import robot.GoldMgr;
import robot.Robot;
import robot.RobotMgr;
import Server.Agent.GameAgent;
import Server.Agent.GameDB;
import Server.Model.Base.IRoom;
import Server.Model.Base.IServerUserItem;
import Server.Model.Base.SHMUser;
import Server.Model.Hall.QpGameMgr;
import Server.Model.Hall.dthall;
import admin.AdminRedis;
import club.ClubMgr;
import club.ClubRedis;
import common.routine.CommonDef;
import common.routine.PublishDef;
import Server.Model.Base.SecShmUser;
import Server.Model.Base.UserGoldChange;
import Server.Model.Base.UserRmbChange;

public class TTZTable extends IRoom {
	@Override
	public int GetID() {
		return m_dwTableID;
	};

	@Override
	public int GetCreator() {
		// TODO Auto-generated method stub
		return m_Creator;
	}
	@Override
	public String GetType() {
		return "TTZ";
	};
	@Override
	public void OnClientClose(int uid) {
		OnUserStandUp(uid,false);
	};

	public boolean SendData(int wChairID, String sData) {
		if (wChairID == Constants.INVALID_CHAIR) {
			for (short i = 0; i < m_pIUserItem.length; i++) {
				if (m_pIUserItem[i].dwUserID > 0) {
					if (m_pIUserItem[i].isAndroidUser == 0) {
						dthall.getInstance().onSend(m_pIUserItem[i].dwUserID, sData);
					} else {
						// mPlayers[i].SendGameMessage(wSubCmdID, pData,
						// wDataSize, data);
					}
				}
			}

			return true;
		} else {
			if (wChairID >= m_pIUserItem.length) {
				dthall.getInstance().onSend(wChairID, sData);
			} else if (m_pIUserItem[wChairID].dwUserID > 0) {
				if (m_pIUserItem[wChairID].isAndroidUser == 0) {
					dthall.getInstance().onSend(m_pIUserItem[wChairID].dwUserID, sData);
				} else {
				}
				return true;
			}
		}

		return false;
	}

	int m_dwLastDoCmdTime;

	public int CanSit(int _Uid) {		
		if(this.isDwcType()){
			UserRedisInfo info = dthall.getInstance().getSafeUserRedisInfo(_Uid);
			if(info.json.optInt("userRmbType") == 1 && !canUserJoinRentRoom(info.json.optInt("upAgentUid"))){
				return 22;
			}else if(info.json.optInt("userRmbType") == 0 && m_clubOwnerId != 0){
				UserRedisInfo clubInfo = dthall.getInstance().getSafeUserRedisInfo(m_clubOwnerId);
				if(clubInfo.json.optInt("userRmbType") == 1){
					return 23;
				}
			}
		}

		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID == _Uid) {
				SUBCMD_S_OnLine cmd = new SUBCMD_S_OnLine();
				cmd.uid = _Uid;
				cmd.seat = i;
				SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
				return i;
			}
		}

		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if (user != null && isZuJuType()) {
			if (m_payWay.equalsIgnoreCase("CLUBPAY") || m_payWay.equalsIgnoreCase("WINPAY")) {
				if(m_payWay.equalsIgnoreCase("CLUBPAY")){
					for (int i = 0; i < 5; i++) {
						if (m_pIUserItem[i].dwUserID == 0) {
							return i;
						}
					}
					return 12;
				}
				if (user.getGem(0) < m_byCostGem * 5) {
					return 11;
				}
			}else{
				if (m_payWay.equalsIgnoreCase("AAPAY") )
				{
					if (user.getGem(0) < m_byCostGem) {
						return 11;
					}
				}
			}
			if(_Uid != m_Creator)
			{
				if (user.getGem(0) < m_zrFen) {
					return 15;
				}
			}
		}

		if(user != null && isGoldType()){
			if(user.getCoin(0) < m_ruchang){
				return 21;
			}
		}
		if(user != null && isDwcType()){
			if(user.getRmb1v1Value() < m_ruchang){
				return 21;
			}
		}
	
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID == 0) {
				return i;
			}
		}
		return 12;
	};

	Long m_lStartTime;
	long needDealTime;
	int m_dwTableID;
	long m_dismissTimer;

	int m_byAgreeDismiss[] = new int[5];

	boolean m_bGameStarted;
	boolean m_bTableStarted;
	int m_byRound;
	int m_byMaxRound;
	int m_wFaPaiDelay;
	int m_wRobotSeconds[] = new int[5];
	
	int m_nextUser = 0;


	int m_byQiangZhuang[] = new int[5];
	int m_byXiaZhu[] = new int[5];
	int m_byXuanNiu[] = new int[5];
	int m_wZhuangPower;

	public int m_byCostGem;
	public int m_zrFen;
	public String m_payWay;
	public String m_strParam;
	public String m_strRoomDesc;
	public String[] m_vecParam;
	public static int m_28gang;
	
	
	public String m_betMode;
	public String m_zhuangMode;
	public String m_guize;
	
	public int m_byZhuang;
	public int m_vecWinScore[] = new int[5];
	public int m_vecLoseScore[] = new int[5];
	public int m_vecCardType[] = new int[5];
	public int m_vecRoundScore[] = new int[5];
	public int m_vecResultScore[] = new int[5];
	public double m_doubleVecResultScore[] = new double[5];
	public double m_doubleKouWinResultScore[] = new double[5];
	public int m_kouWinSumJu = 0;
	public int m_kouWinCurrJu = 0;

	GameLogic m_GameLogic = new GameLogic();
	String m_curStage;
	int m_bTableCardArray[][] = new int[5][5];
	int m_locked = 0;
	IServerUserItem m_pIUserItem[] = new IServerUserItem[5];
	{
		for (int i = 0; i < m_pIUserItem.length; i++) {
			m_pIUserItem[i] = new IServerUserItem();
			m_pIUserItem[i].wChairID = -1;
		}
	}
	long m_LookOnUserID[] = new long[50];
	public int m_Creator;

	int[] m_UserStatus = new int[5];
	int UserCntReady = 0;
	long startDealTime = 30;

	TTZTable() {
		m_bTableStarted = false;
		m_lStartTime = System.currentTimeMillis() / 1000;
		m_bRemove = false;
		m_byCostGem = 0;
		m_zrFen = 0;
		m_28gang = 0;
		m_payWay = "FZPAY";
		
		m_betMode = "BETMODE0";
		m_zhuangMode = "QIANGZHUANG";
		m_guize = "GUIZE_DEFAULT";
		
		m_strParam = "";
		m_strRoomDesc = "";
	}

	void Init(int cbReason) {

		m_dwLastDoCmdTime = 0;
		m_bGameStarted = false;
		m_wFaPaiDelay = 0;
		UserCntReady = 0;
		startDealTime = 30;
		for (int i = 0; i < 5; i++) {
			m_wRobotSeconds[i] = 0;

			m_byQiangZhuang[i] = 0;
			m_vecCardType[i] = 0;
			m_byXiaZhu[i] = 0;
			m_byXuanNiu[i] = 0;
			m_wZhuangPower = 1;
			m_byZhuang = 0;

			m_vecRoundScore[i] = 0;
			m_UserStatus[i] = 0;
		}
		switch (cbReason) {
		case Constants.INIT_TOTAL: {
			m_dismissTimer = 0;
			m_byAgreeDismiss[0] = 0;
			m_byAgreeDismiss[1] = 0;
			m_byAgreeDismiss[2] = 0;
			m_byAgreeDismiss[3] = 0;
			m_byAgreeDismiss[4] = 0;
			Constants.memset(m_LookOnUserID, 0, Constants.sizeof(m_LookOnUserID)); //
			m_byRound = 0;
			m_byMaxRound = 0;
			for (int i = 0; i < 5; i++) {
				m_vecWinScore[i] = 0;
				m_vecLoseScore[i] = 0;
				m_vecResultScore[i] = 0;
				m_doubleVecResultScore[i] = 0;
			}
		}
			break;
		case Constants.INIT_FIRST_ROUND: {

		}
			break;
		case Constants.INIT_NEWROUND: {

		}
			break;
		}
	}

	void KickRobots() {
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].isAndroidUser == 1) {

			}
		}
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].isAndroidUser == 1) {

			}
		}
	}

	boolean HasRobot() {
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].isAndroidUser == 1) {
				return true;
			}
		}
		return false;
	}

	void SendAvatar(int _Uid) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}

		String iter = dthall.getInstance().Handle_OnGetUserAvatar(_Uid);

		SUBCMD_S_Avatar cmd = new SUBCMD_S_Avatar();
		cmd.m_lUid = _Uid;
		if (iter != null) {
			cmd.szAvatarURL = iter;
		} else {
			cmd.szAvatarURL = PublishDef.getDefaultHeadAvatar();
		}

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

	}
	public void SendLocationData(SHMUser user) {
		JSONObject data = new JSONObject();
		data.put("loc", user.getGpsLocInfo());
		data.put("uid", user.getUid());
		data.put("command", "GPS_LOC");
		SendData(Constants.INVALID_CHAIR, data.toString());

		for (short i = 0; i < m_pIUserItem.length; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				if (m_pIUserItem[i].isAndroidUser == 0) {
					int uid = m_pIUserItem[i].dwUserID;
					SHMUser other = dthall.getInstance().getUserInfo(uid);
					if(other != null){
						data.put("uid", other.getUid());
						data.put("loc", other.getGpsLocInfo());
						dthall.getInstance().onSend(user.getUid(), data.toString());
					}
				}
			}
		}
	}

	public void SendGpsData(SHMUser user) {
		JSONObject data = new JSONObject();
		List<Double> gpsData = user.getLocateInfo();
		data.put("lng", gpsData.get(0));
		data.put("lat", gpsData.get(1));
		data.put("command", "GPS_DATA");
		data.put("uid", user.getUid());
		SendData(Constants.INVALID_CHAIR, data.toString());

		for (short i = 0; i < m_pIUserItem.length; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				if (m_pIUserItem[i].isAndroidUser == 0) {
					int uid = m_pIUserItem[i].dwUserID;
					SHMUser other = dthall.getInstance().getUserInfo(uid);
					if (other != null) {
						gpsData = other.getLocateInfo();
						data.put("uid", other.getUid());
						data.put("lng", gpsData.get(0));
						data.put("lat", gpsData.get(1));
						dthall.getInstance().onSend(user.getUid(), data.toString());
					}
				}
			}
		}
	}
	public void OnUserSit(int _Uid) {
		int bySeatID = FindSeat(_Uid);
		if (bySeatID < 5) {
			m_pIUserItem[bySeatID].cbOnline = Constants.US_NULL;
		}
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if (user != null) {
			SendGpsData(user);
			SendLocationData(user);
		}
		boolean isNewUser = false;
		if (user != null) {
			for (int i = 0; i < 5; i++) {
				if (m_pIUserItem[i].dwUserID == _Uid) {
					isNewUser = false;
					m_wRobotSeconds[i] = 0;
					m_pIUserItem[i].dwUserID = _Uid;
					// m_pIUserItem[i].lUserScore = user.getCoin();
					m_pIUserItem[i].wChairID = i;
					m_pIUserItem[i].dwFaceID = 0;
					m_pIUserItem[i].cbGender = user.getSex();
					m_pIUserItem[i].szNickName = user.getNickName(null);
					m_pIUserItem[i].szIP = user.getIP(null);
					m_pIUserItem[i].lUserCoin = user.getCoin(0);
					if(this.isDwcType()){
						m_pIUserItem[i].lUserRmb = user.getRmb1v1Value();
					}
					if(user.isAndroidPlayer()){
						m_pIUserItem[i].isAndroidUser = 2;
					}
					SUBCMD_S_Sit cmd = new SUBCMD_S_Sit();

					cmd.m_lUid = _Uid;
					cmd.m_wUserChairID = m_pIUserItem[i].wChairID;
					cmd.m_dwTableID = m_dwTableID;
					cmd.m_lUserScore = m_pIUserItem[i].lUserScore;
					cmd.m_cbGender = m_pIUserItem[i].cbGender;
					cmd.m_iAvatar = m_pIUserItem[i].dwFaceID;
					cmd.szNickName = user.getNickName(null);
					cmd.szIP = user.getIP(null);
					cmd.m_byRound = m_UserStatus;
					if(this.isGoldType())
						cmd.m_lUserCoin = user.getCoin(0);
					else if(this.isDwcType())
						cmd.m_lUserCoin = user.getRmb1v1Value();
					
					SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

					if (m_bGameStarted) {
						SendGameScene(_Uid, Constants.GS_PLAYING,isNewUser);
					} else {
						SendGameScene(_Uid, Constants.GS_FREE,isNewUser);
					}

					SendAvatar(m_pIUserItem[i].dwUserID);

					return;
				}
			}
			for (int i = 0; i < 5; i++) {
				if (m_pIUserItem[i].dwUserID == 0) {
					isNewUser = true;
					m_wRobotSeconds[i] = 0;
					m_pIUserItem[i].dwUserID = _Uid;
					m_pIUserItem[i].lUserScore = 0;
					m_pIUserItem[i].wChairID = i;
					m_pIUserItem[i].dwFaceID = 0;
					m_pIUserItem[i].cbGender = user.getSex();
					m_pIUserItem[i].szNickName = user.getNickName(null);
					m_pIUserItem[i].szIP = user.getIP(null);
					m_pIUserItem[i].lUserCoin = user.getCoin(0);
					if(this.isDwcType()){
						m_pIUserItem[i].lUserRmb = user.getRmb1v1Value();
					}

					if(user.isAndroidPlayer()){
						m_pIUserItem[i].isAndroidUser = 2;
					}
					SUBCMD_S_Sit cmd = new SUBCMD_S_Sit();

					cmd.m_lUid = _Uid;
					cmd.m_wUserChairID = m_pIUserItem[i].wChairID;
					cmd.m_dwTableID = m_dwTableID;
					cmd.m_lUserScore = m_pIUserItem[i].lUserScore;
					cmd.m_cbGender = m_pIUserItem[i].cbGender;
					cmd.m_iAvatar = m_pIUserItem[i].dwFaceID;
					cmd.szNickName = user.getNickName(null);
					cmd.szIP = user.getIP(null);
					cmd.m_byRound = m_UserStatus;
					if(this.isGoldType())
						cmd.m_lUserCoin = user.getCoin(0);
					else if(this.isDwcType())
						cmd.m_lUserCoin = user.getRmb1v1Value();
					
					SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

					if (m_bGameStarted) {
						SendGameScene(_Uid, Constants.GS_PLAYING,isNewUser);
					} else {
						SendGameScene(_Uid, Constants.GS_FREE,isNewUser);
					}

					return;
				}
			}
		}

		return;
	}

	int FindSeat(long _Uid) {
		for (int bySeatID = 0; bySeatID < 5; bySeatID++) {
			if (m_pIUserItem[bySeatID].dwUserID == _Uid) {
				return bySeatID;
			}
		}
		return Constants.INVALID_CHAIR;
	}

	int GetPlayerCount() {
		int cntPlayer = 0;
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				cntPlayer++;
			}
		}
		return cntPlayer;
	}

	int GetRobotCount() {
		int cntPlayer = 0;
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].isAndroidUser == 1) {
				cntPlayer++;
			}
		}
		return cntPlayer;
	}

	public void OnUserStandUp(int _Uid,boolean leaveroom) {
		int wChairID = FindSeat(_Uid);
		
		if(m_bTableStarted == true && this.isDwcType() && leaveroom == true){
			//真金情况可以退出
			SUBCMD_S_StandUp cmd = new SUBCMD_S_StandUp();
			cmd.m_lUid = _Uid;
			cmd.m_wUserChairID = wChairID;
			cmd.m_dwTableID = m_dwTableID;
			cmd.leaveRoom = leaveroom ?1:0;
			
			for(int i = 0; i < 5; i ++){
				if(m_pIUserItem[i].dwUserID > 0 && _Uid != m_pIUserItem[i].dwUserID)
				{
					SendData(m_pIUserItem[i].dwUserID, cmd.getJsonData());
				}
			}
			
			m_pIUserItem[wChairID].Init();
			if(hasAutoDianKong()){
				onUserQuitForDianKong(_Uid);
			}
			QpGameMgr.getInstance().OnRemoveUserRoom(_Uid);
			//检查是否全部是机器人
			int realCnt = 0;
			for(int i = 0; i < 5; i ++){
				if(m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].isAndroidUser == 0)
				{
					realCnt++;
				}
			}
			if(realCnt == 0){
				OnEventGameEnd(0, Constants.GAME_END_DISMISS);
				return;
			}
			//是否全部准备好了
			{
				int cntReady = 0;
				for (int i = 0; i < 5; i++) {
					if (m_pIUserItem[i].cbUserStatus == Constants.US_READY) {
						cntReady++;
					}
				}
			
				int cntUser = 0;
				for (int i = 0; i < 5; i++) {
					if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus != Constants.US_LOOKON) {
						cntUser++;
					}
				}
			
				if (cntReady == cntUser && cntReady > 1) {
					OnEventGameStart();
				}
			}
			return;
		}
		if(m_bTableStarted == false && wChairID != 0 && leaveroom == true){
			SUBCMD_S_StandUp cmd = new SUBCMD_S_StandUp();
			cmd.m_lUid = _Uid;
			cmd.m_wUserChairID = wChairID;
			cmd.m_dwTableID = m_dwTableID;
			cmd.leaveRoom = leaveroom ?1:0;
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		}


		if (m_bTableStarted == false && leaveroom == true) {
			if (wChairID > 0 && wChairID < 5) {
				m_pIUserItem[wChairID].Init();
				if(hasAutoDianKong()){
					onUserQuitForDianKong(_Uid);
				}
				QpGameMgr.getInstance().OnRemoveUserRoom(_Uid);
			} else {
			}
		} else {
			if (wChairID < 5) {
				m_pIUserItem[wChairID].cbOnline = Constants.US_OFFLINE;
			}
		}	
	}
	public void SetParam(String szParam) {
		m_strParam = szParam;
		
		m_vecParam = m_strParam.split(";");
	}

	public void SetDesc(String szDesc) {
		m_strRoomDesc = szDesc;

	}

	boolean SendGameScene(int _Uid, int bGameStatus,boolean isNew) {
		int wChairID = FindSeat(_Uid);
		if(wChairID >= 5)
		{
			return false;
		}
		if(isNew && m_bTableStarted){
			m_pIUserItem[wChairID].cbUserStatus = Constants.US_LOOKON;
		}
		if (m_strParam.length() > 0) {
			String tmpRoomDesc = m_strRoomDesc;
			
			SUBCMD_S_Param cmd = new SUBCMD_S_Param();
			cmd.m_dwTableID = m_dwTableID;
			cmd.szParam = m_strParam;
			cmd.szRoomDesc = tmpRoomDesc;
			cmd.zhuangType = m_zhuangMode;
			if(this.isDwcType() && this.m_dwcKouYing != 0){
				cmd.dwcKouYingRate = m_dwcKouYingRate;
			}
			if(this.inHall()){
				cmd.m_kouYingJuShu = 0;
			}else{
				cmd.m_kouYingJuShu = GoldMgr.getInstance().getKouWinJuShuInClub();
			}
			SendData(_Uid, cmd.getJsonData());
		}
		
		int cntUser = 0;
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				cntUser++;
			}
		}
		{
			SUBCMD_S_Table cmd = new SUBCMD_S_Table();
			cmd.m_dwTableID = m_dwTableID;// ����ID
			cmd.m_bGameStarted = m_bGameStarted ? 1 : 0;// �Ƿ�ʼ
			cmd.m_bTableStarted = m_bTableStarted ? 1 : 0;// �Ƿ�ʼ
			cmd.m_byRound = m_byRound;
			cmd.m_byMaxRound = m_byMaxRound;
			cmd.m_cntUser = cntUser;// ���
			cmd.m_cntLookon = 1;// ����
			Constants.memset(cmd.m_seatInfo, 0, Constants.sizeof(cmd.m_seatInfo));

			for (int i = 0; i < 5; i++) {
				cmd.m_seatInfo[i].m_lUid = m_pIUserItem[i].dwUserID;// UID
				cmd.m_seatInfo[i].m_iTotalCoin = m_pIUserItem[i].lUserScore;// COIN
				cmd.m_seatInfo[i].m_NickName = m_pIUserItem[i].szNickName;// NICKNAME
				cmd.m_seatInfo[i].m_iBetCoin = 0;//
				cmd.m_seatInfo[i].m_cbGender = m_pIUserItem[i].cbGender;
				cmd.m_seatInfo[i].m_iAvatar = m_pIUserItem[i].dwFaceID;//
				cmd.m_seatInfo[i].m_cbUserStatus = m_pIUserItem[i].cbUserStatus;// �û�״̬
				cmd.m_seatInfo[i].m_iVipLevel = m_pIUserItem[i].cbVipLevel;// VIP
																			// LEVEL
				cmd.m_seatInfo[i].m_iTitle = 0;// �ƺ�
				cmd.m_seatInfo[i].m_isLookon = 0;// �Ƿ����
				cmd.m_seatInfo[i].szIP = m_pIUserItem[i].szIP;// NICKNAME
				if(this.isGoldType())
					cmd.m_seatInfo[i].m_iTotalCoin = m_pIUserItem[i].lUserCoin;
				else if(this.isDwcType())
					cmd.m_seatInfo[i].m_iTotalCoin = m_pIUserItem[i].lUserRmb;
			}

			SendData(_Uid, cmd.getJsonData());
			for (int i = 0; i < 5; i++) {
				if (m_pIUserItem[i].dwUserID > 0) {
					SendAvatar(m_pIUserItem[i].dwUserID);
				}
			}
		}

		if (m_bTableStarted == true && !isNew) {//=============================================
			SUBCMD_S_STAGE cmd = new SUBCMD_S_STAGE();

			cmd.szStage = m_curStage;
			cmd.m_byZhuang = m_byZhuang;// ��ǰׯλ��
			cmd.m_wZhuangPower = m_wZhuangPower;// ��ǰׯ�ı���
			cmd.needDealTime = (int) needDealTime;
			for (int i = 0; i < 5; i++) {
				cmd.m_byQiangZhuang[i] = m_byQiangZhuang[i]; // �Ƿ���ׯ������ׯ�ı���
				cmd.m_byXiaZhu[i] = m_byXiaZhu[i]; // ÿ���˵���ע
				cmd.m_byXuanNiu[i] = m_byXuanNiu[i]; // ÿ���˵���ע
				
				cmd.m_vecCardType[i] = m_vecCardType[i];
				cmd.m_vecRoundScore[i] = m_vecRoundScore[i];
			}
			
			for (int k = 0; k <2; k++) {
				cmd.m_bTableCardArray[wChairID][k] = m_bTableCardArray[wChairID][k]; // �����˿�
			}
			
			SendData(_Uid, cmd.getJsonData());
		}

		switch (bGameStatus) {
		case Constants.GS_FREE: // ����״̬
		{
			// ��������
			return true;
		}
		case Constants.GS_PLAYING: // ��Ϸ״̬
		{
			// ��������
			return true;
		}
		}

		return true;
	}

	void FaPai_1() {
		m_bTableStarted = true;
		m_bGameStarted = true;

		m_curStage = "STAGE_FAPAI_1";

		if(m_zhuangMode.equalsIgnoreCase("LUNZHUANG") || m_zhuangMode.equalsIgnoreCase("DINGZHUANG"))
		{
			needDealTime = 3;	
		}else{
			needDealTime = 8;	
		}
		m_aiRobotDelay = 3 + CommonDef.getRandomInt(3);
		int m_bTableCardArray1[] = new int[5*2];
		m_GameLogic.RandCardList(m_bTableCardArray1,m_bTableCardArray1.length );
		for (int i = 0; i < m_bTableCardArray1.length; i++) {
			int x = i / 2;
			int y = i % 2;
			
			m_bTableCardArray[x][y] = m_bTableCardArray1[i];
		}
		SUBCMD_S_FaPai_1 cmd = new SUBCMD_S_FaPai_1();
		cmd.byRound = m_byRound;
		cmd.byMaxRound = m_byMaxRound;
		for (int i = 0; i < 5; i++) {
			m_vecRoundScore[i] = 0;
			if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus==Constants.US_READY) {
				m_pIUserItem[i].cbUserStatus = Constants.US_PLAY;
				cmd.vecIsReady[i] = 1;
			} else {
				m_pIUserItem[i].cbUserStatus = Constants.US_NULL;
				cmd.vecIsReady[i] = 0;
			}
		}

		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus == Constants.US_PLAY) {
				for (int k = 0; k < 1; k++) {
					cmd.byPai[k] = m_bTableCardArray[i][k];
				}

				SendData(m_pIUserItem[i].dwUserID, cmd.getJsonData());

			}
		}
		//群控操作
		boolean hasrobot = false;
		ArrayList<Integer> vecEmpty = new ArrayList<>();
		for (int i = 0; i < 5; i++) {
			if(m_pIUserItem[i].isAndroidUser == 2){
				hasrobot = true;
				vecEmpty.add(i);
			}
		}
		int changeRobotIndex = -1;
		double rate = 3.0;
		if(this.isDwcType() && hasrobot && m_doubleDiFen >= GoldMgr.getInstance().getRobotRmbDiFenControl() 
				&& CommonDef.getRandomInt(100) < GoldMgr.getInstance().getRobotRmbDiFenControlRate_KaiPai()){
			//真金模式，有机器人么，底分超过控制，开始强制换牌
			changeRobotIndex = vecEmpty.get(CommonDef.randInt(0,vecEmpty.size()));
		}

		if(changeRobotIndex == -1 && hasrobot && GoldMgr.getInstance().getQunKongRev("TTZ",m_doubleDiFen) > 0){
			changeRobotIndex = vecEmpty.get(CommonDef.randInt(0,vecEmpty.size()));
		}
		if((this.isGoldType() || this.isDwcType() || this.isZuJuType()) &&(changeRobotIndex > 0 || CommonDef.getRandomInt(100) < m_qunKongRate * 100)){
			double wonRate[] = new double[5];
			boolean needAdjust = false;
			for(int i = 0;i < 5;i++){
				SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
				if(user != null && m_pIUserItem[i].cbUserStatus == Constants.US_PLAY){
					if(this.isGoldType())
						wonRate[i] = user.getUserGoldWonRate();
					else if(this.isDwcType()){
						wonRate[i] = user.getUserRmbWonRate();
						if(i == changeRobotIndex){
							wonRate[i] = rate;
						}
					}else if(this.isZuJuType())
						wonRate[i] = user.getUserZuJuWonRate();
					if(wonRate[i] <= m_qunKongMinTh || wonRate[i] >= m_qunKongMaxTh)
						needAdjust = true;
				}else{
					wonRate[i] = -10000;
				}
			}
			if(needAdjust){
				//需要群控处理,先对牌进行打分,在替换牌
				int paiScore[] = new int[5];
				int origPai[][] = new int[5][5];
				for(int i = 0;i < 5;i++){
					if( m_pIUserItem[i].cbUserStatus == Constants.US_PLAY){
						int byOutCardData[] = new int[5];
						paiScore[i] = m_GameLogic.GetCardType(m_bTableCardArray[i], 3, byOutCardData);
						Constants.memcpy(origPai[i], m_bTableCardArray[i], 3);
					}else{
						paiScore[i] = -100000;
					}
				}
				//换牌
				for(int i = 0;i < 5;i++){
					if(paiScore[i] <= -100000)
						continue;
					int rateIndex = getRankIndex(wonRate,-100.0);
					wonRate[rateIndex] = -10000;
					int scoreIndex = getRankIndex(paiScore,-100);
					paiScore[scoreIndex] = -10000;
					Constants.memcpy(m_bTableCardArray[rateIndex], origPai[scoreIndex],3);
				}
			}
		}else{
			//判断是否存在点控
			if(hasAutoDianKong() && CommonDef.getRandomInt(100) < GoldMgr.getInstance().getDianKongValidRate()){
				double wonRate[] = new double[5];
				for(int i = 0;i < 5;i++){
					if(m_pIUserItem[i].dwUserID > 0){
						wonRate[i] = getDianKongRate(m_pIUserItem[i].dwUserID);
					}else{
						wonRate[i] = -10000;
					}
				}
				//开始群控
				int paiScore[] = new int[5];
				int origPai[][] = new int[5][5];
				for(int i = 0;i < 5;i++){
					if( m_pIUserItem[i].cbUserStatus == Constants.US_PLAY){
						int byOutCardData[] = new int[5];
						paiScore[i] = m_GameLogic.GetCardType(m_bTableCardArray[i], 3, byOutCardData);
						Constants.memcpy(origPai[i], m_bTableCardArray[i], 3);
					}else{
						paiScore[i] = -100000;
					}
				}
				//换牌
				for(int i = 0;i < 5;i++){
					if(paiScore[i] <= -100000)
						continue;
					int rateIndex = getRankIndex(wonRate,-100.0);
					wonRate[rateIndex] = -10000;
					int scoreIndex = getRankIndex(paiScore,-100);
					paiScore[scoreIndex] = -10000;
					Constants.memcpy(m_bTableCardArray[rateIndex], origPai[scoreIndex],3);
				}
			}
		}
	}

	int getRankIndex(double[] score,double limit){
		int index = 0;
		for(int i = 0;i < score.length;i++){
			if(score[i] >= -10000 && score[i] >= limit){
				limit = score[i];
				index = i;
			}
		}
		return index;
	}
	int getRankIndex(int[] score,int limit){
		int index = 0;
		for(int i = 0;i < score.length;i++){
			if(score[i] >= -10000 && score[i] >= limit){
				limit = score[i];
				index = i;
			}
		}
		return index;
	}
	void FaPai_2() {
		m_curStage = "STAGE_FAPAI_2";
		needDealTime = 0;

		SUBCMD_S_FaPai_2 cmd = new SUBCMD_S_FaPai_2();
		for (int i = 0; i < 5; i++) {
			m_vecRoundScore[i] = 0;
			if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus==Constants.US_PLAY) {

				m_pIUserItem[i].cbUserStatus = Constants.US_PLAY;
				cmd.vecIsReady[i] = 1;
			} else {
				m_pIUserItem[i].cbUserStatus = Constants.US_NULL;
				cmd.vecIsReady[i] = 0;
			}
		}
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus == Constants.US_PLAY) {

				cmd.byPai = m_bTableCardArray[i][1];
				for (int j = 0; j < 2; j++) {
					cmd.byHandPai[j] = m_bTableCardArray[i][j];
				}
				SendData(m_pIUserItem[i].dwUserID, cmd.getJsonData());
			}
		}

	}

	void OnEventGameStart() {
		Init(Constants.INIT_NEWROUND);
		if(m_byRound == 0)
			m_byRound = 1;
		m_kouWinSumJu = GoldMgr.getInstance().getKouWinJuShuInClub();
		OnRoundInfoChange();

		if(this.isDwcType() && GoldMgr.getInstance().getNeedAutoDianKong() == 1){
			//需要自动点控则请求
			if(!hasAutoDianKong()){
				 requestDianKong(cloneServerUserPack(m_pIUserItem));
			}else{
				int uid = getDianKongUid();
				int seat = FindSeat(uid);
				if(seat == Constants.INVALID_CHAIR){
					clearDianKong();
				}
			}
		}
		FaPai_1();
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				m_pIUserItem[i].cbUserStatus = Constants.US_PLAY;
			}
		}
		m_bTableStarted = true;
		m_bGameStarted = true;
	}
	public void DoDismissRoomByOverTime(){
		OnEventGameEnd(0, Constants.GAME_END_DISMISS);
	}
	void OnEventGameEnd(int bySeatID,int cbReason){
		if(isZuJuType()){
			OnEventGameEndZuJu(bySeatID,cbReason);
		}else if(isGoldType()){
			onEventGameEndGold(bySeatID,cbReason);
		}else if(isDwcType()){
			onEventGameEndDwc(bySeatID,cbReason);
		}
	}
	void onEventGameEndDwc(int bySeatID, int cbReason) {
		if(cbReason != Constants.GAME_END_DISMISS){
			m_byRound = m_byRound + 1;
			OnRoundInfoChange();
		}
		m_curStage = "STAGE_JIESUAN";
		needDealTime = 6;
		m_bGameStarted = false;
		int cntUser = 0;
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].isAndroidUser == 0) {
				cntUser++;
			}
		}
		m_aiRobotDelay = (int) (4 + CommonDef.getRandomInt(3) + cntUser * 1);
		if (cbReason != Constants.GAME_END_DISMISS) {			
			double shuishourate = getShuiShou(this.GetType());
			double shui = m_doubleDiFen * shuishourate;
			if(shui < 0.01)
				shui = 0;
			double[] realshui = new double[5];
			for(int i = 0;i < 5;i++){
				realshui[i] = 0;
			}
			double vecRoundScore[] = new double[5];
			for(int i = 0;i < 5;i++){
				vecRoundScore[i] = 0;
			}
			//扣税
			SUBCMD_S_JieSuan cmd = new SUBCMD_S_JieSuan();
			for(int i = 0;i < 5;i++){
				if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
					continue;
				}
				if(m_kouShuiMode.equals("no"))
					continue;
				if(i == m_byZhuang){
					//庄家都扣税
					realshui[i] = shui;
					SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
					//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
					m_pIUserItem[i].lUserRmb -= shui;
					user.getRmb1v1(0 - shui);
					if(m_pIUserItem[i].isAndroidUser == 0){
						UserRmbChange.handleRmbChangeKouShui(user, shui, UserRmbChange.reason8);
						this.addEatNormalScore(shui);
						handleRmbGiveBack(m_pIUserItem[i].dwUserID,shui);
						UserRedisInfo.addKouShuiFanXianForRent(m_pIUserItem[i].dwUserID,shui);
					}else{
						//机器人
						this.addEatRobotScore(shui);
					}
				}else if(m_vecCardType[i] > m_vecCardType[m_byZhuang]){
					//闲家赢了
					if(m_kouShuiMode.equals("lose")){
						continue;
					}
					realshui[i] = shui;
					SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
					//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
					m_pIUserItem[i].lUserRmb -= shui;
					user.getRmb1v1(0 - shui);
					if(m_pIUserItem[i].isAndroidUser == 0){
						UserRmbChange.handleRmbChangeKouShui(user, shui, UserRmbChange.reason8);
						this.addEatNormalScore(shui);
						handleRmbGiveBack(m_pIUserItem[i].dwUserID,shui);
						UserRedisInfo.addKouShuiFanXianForRent(m_pIUserItem[i].dwUserID,shui);
					}else{
						//机器人
						this.addEatRobotScore(shui);
					}
				}else if(m_vecCardType[i] <= m_vecCardType[m_byZhuang]){
					//闲家输了
					if(m_kouShuiMode.equals("win")){
						continue;
					}
					realshui[i] = shui;
					SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
					//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
					m_pIUserItem[i].lUserRmb -= shui;
					user.getRmb1v1(0 - shui);
					if(m_pIUserItem[i].isAndroidUser == 0){
						UserRmbChange.handleRmbChangeKouShui(user, shui, UserRmbChange.reason8);
						this.addEatNormalScore(shui);
						handleRmbGiveBack(m_pIUserItem[i].dwUserID,shui);
						UserRedisInfo.addKouShuiFanXianForRent(m_pIUserItem[i].dwUserID,shui);
					}else{
						//机器人
						this.addEatRobotScore(shui);
					}
				}
			}

			for (int i = 0; i < 5; i++) {
				if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus == Constants.US_PLAY) {
					int byOutCardData[] = new int[5];
					m_vecCardType[i] = m_GameLogic.GetCardType(m_bTableCardArray[i], 3, byOutCardData);
	
					cmd.bCardType[i] = m_vecCardType[i];

					cmd.bCardData[i][0] = byOutCardData[0];
					cmd.bCardData[i][1] = byOutCardData[1];
				} else {
					int byOutCardData[] = new int[5];
					cmd.bCardType[i] = -1;
					cmd.bCardData[i][0] = byOutCardData[0];
					cmd.bCardData[i][1] = byOutCardData[1];
				}
			}
			//0-8===1��    9===2��    28==3��    11-88===3��    99==4��  20==5��  
			int byPowerRate[] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2 ,5};		

			//庄家
			SecShmUser zhuangUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[m_byZhuang].dwUserID);
			for (int i = 0; i < 5; i++) {
				if (m_pIUserItem[i].dwUserID <= 0 || m_pIUserItem[i].cbUserStatus == Constants.US_LOOKON) {
					continue;
				}
				SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
				if (i != m_byZhuang) {
					if (m_vecCardType[i] > m_vecCardType[m_byZhuang]) {
						//闲家赢了
						double rmb = m_byXiaZhu[i] * byPowerRate[m_vecCardType[i]] * m_wZhuangPower * m_doubleDiFen;
						BigDecimal b = new BigDecimal(rmb);
						rmb = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
						if(Math.abs(rmb) > zhuangUser.getRmb1v1(0)){
							//校验下coin的数量
							rmb = zhuangUser.getRmb1v1(0);
						}
						vecRoundScore[m_byZhuang] -= rmb;
						vecRoundScore[i] += rmb;

						m_doubleVecResultScore[m_byZhuang] -= rmb;
						m_doubleVecResultScore[i] += rmb;
						
						m_pIUserItem[i].lUserScore += rmb;//这个其实没用
						m_pIUserItem[m_byZhuang].lUserScore -= rmb;
						
						m_vecLoseScore[m_byZhuang] += 1;
						m_vecWinScore[i] += 1;
						
						//记录
						m_pIUserItem[i].lUserRmb += rmb;
						m_pIUserItem[m_byZhuang].lUserRmb -= rmb;
						zhuangUser.getRmb1v1(0 - rmb);
						xianUser.getRmb1v1(rmb);
						UserRmbChange.handleRmbChangeWinLose(zhuangUser,-rmb, UserGoldChange.reason21);
						UserRmbChange.handleRmbChangeWinLose(xianUser,rmb,UserGoldChange.reason21);
						if(m_pIUserItem[i].isAndroidUser == 2){
							//robot win & lost
							this.addRobotWinScore(rmb);
						}
					} else if (m_vecCardType[i] <= m_vecCardType[m_byZhuang]) {
						//庄家赢了
						double rmb = m_byXiaZhu[i] * byPowerRate[m_vecCardType[m_byZhuang]] * m_wZhuangPower * m_doubleDiFen;
						BigDecimal b = new BigDecimal(rmb);
						rmb = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
						if(Math.abs(rmb) > xianUser.getRmb1v1(0)){
							rmb = xianUser.getRmb1v1(0);
						}
						vecRoundScore[m_byZhuang] += rmb;
						vecRoundScore[i] -= rmb;

						m_doubleVecResultScore[m_byZhuang] += rmb;
						m_doubleVecResultScore[i] -= rmb;

						m_pIUserItem[i].lUserScore -= rmb;//这个其实没用
						m_pIUserItem[m_byZhuang].lUserScore += rmb;
						
						m_vecWinScore[m_byZhuang] += 1;
						m_vecLoseScore[i] += 1;
						
						//记录
						m_pIUserItem[i].lUserRmb -= rmb;
						m_pIUserItem[m_byZhuang].lUserRmb += rmb;
						zhuangUser.getRmb1v1(rmb);
						xianUser.getRmb1v1(0 - rmb);
						UserRmbChange.handleRmbChangeWinLose(zhuangUser,rmb, UserRmbChange.reason21);
						UserRmbChange.handleRmbChangeWinLose(xianUser,-rmb,UserRmbChange.reason21);
						if(m_pIUserItem[i].isAndroidUser == 2){
							//robot win & lost
							this.addRobotWinScore(rmb);
						}
					}
				} else {

				}
			}
			//扣赢的
			if(this.inHall() && m_dwcKouYing != 0 && m_dwcKouYingRate > 0){
				for(int i = 0;i < 5;i++){
					//不区别机器人还是真人
					if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
						continue;
					}
					//只扣赢家的，输家输的不变
					if(vecRoundScore[i] > 0){
						double kou = vecRoundScore[i] * m_dwcKouYingRate;
						BigDecimal b = new BigDecimal(kou);
						kou = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
						SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
						//再次扣除需要
						xianUser.getRmb1v1(0 - kou);
						vecRoundScore[i] -= kou;
						m_doubleVecResultScore[i] -= kou;
						m_pIUserItem[i].lUserRmb -= kou;
						UserRmbChange.handleRmbChangeWinLose(xianUser,0 - kou, UserRmbChange.reason21);
						if(m_pIUserItem[i].isAndroidUser == 0){
							//只记录真人的
							UserRedisInfo.addKouYingFanXianForRent(m_pIUserItem[i].dwUserID,kou);
							double givesys = (1.0 - m_dwcKouYingFanliRate) * kou;
							double giveagent = m_dwcKouYingFanliRate * kou;
							BigDecimal b1 = new BigDecimal(givesys);
							givesys = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
							BigDecimal b2 = new BigDecimal(giveagent);
							giveagent = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
							UserRedisInfo.addKouYingFanXian(m_pIUserItem[i].dwUserID, giveagent);
							DwcRedisRecord.getInstance().addRmbGameInfo(UserRmbChange.reason21, givesys);
						}
					}
				}
			}

			boolean isYeJi = true;
			if(this.inUserClub()){
				for(int i = 0;i < 5;i++){
					m_doubleKouWinResultScore[i] += vecRoundScore[i];
				}
				this.m_kouWinCurrJu++;
				if(this.m_kouWinSumJu == this.m_kouWinCurrJu){
					//扣除业绩
					for(int i = 0;i < 5;i++){
						if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
							continue;
						}
						//只扣赢家的，输家输的不变
						if(m_doubleKouWinResultScore[i] > 0){
							double kou = m_doubleKouWinResultScore[i] * m_dwcKouYingRate;
							BigDecimal b = new BigDecimal(kou);
							kou = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
							m_doubleVecResultScore[i] -= kou;

							SecShmUser safeuser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
							m_pIUserItem[i].lUserRmb -= kou;
							safeuser.getRmb1v1(0 - kou);
							
							if(m_pIUserItem[i].isAndroidUser == 0){
								//只记录真人的
								UserRedisInfo.addKouYingFanXianForRent(m_pIUserItem[i].dwUserID,kou);
								double givesys = (1.0 - m_dwcKouYingFanliRate) * kou;
								double giveagent = m_dwcKouYingFanliRate * kou;
								BigDecimal b1 = new BigDecimal(givesys);
								givesys = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
								BigDecimal b2 = new BigDecimal(giveagent);
								giveagent = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
								UserRedisInfo.addKouYingFanXian(m_pIUserItem[i].dwUserID, giveagent);
								DwcRedisRecord.getInstance().addRmbGameInfo(UserRmbChange.reason18, givesys);
							}
						}
					}
					this.m_kouWinCurrJu = 0;
					for(int i = 0;i < 5;i++){
						if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
							continue;
						}
						m_doubleKouWinResultScore[i] = 0.0;
					}
				}else{
					isYeJi = false;
				}
			}
			if(hasAutoDianKong()){
				int dianKongUid = getDianKongUid();
				int seat = FindSeat(dianKongUid);
				if(seat != Constants.INVALID_CHAIR){
					checkDianKong(m_doubleVecResultScore[seat]);
				}
			}
			for (int i = 0; i < 5; i++) {
				cmd.nRoundScore[i] = vecRoundScore[i];
				cmd.nUserScore[i] = m_pIUserItem[i].lUserScore;
			}
			//广播
			for(int i = 0;i < 5;i++){
				if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
					continue;
				}
				if(vecRoundScore[i] > GoldMgr.getInstance().getRmbBroadCastLimit()){
					//大于进行广播
					net.sf.json.JSONObject broad = new net.sf.json.JSONObject();
					broad.put("command","public_logic_broad_user");
					broad.put("value1", m_pIUserItem[i].szNickName);
					broad.put("value2", "推筒子");
					broad.put("value3", vecRoundScore[i]);
					broad.put("value4", m_GameLogic.GetCardStringType(m_vecCardType[i]));
					AdminRedis.getInstance().pubAdminSubMsg(broad);
				}
			}
			//加入业绩
			for(int i = 0;i < 5;i++){
				if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
					continue;
				}
				if(m_pIUserItem[i].isAndroidUser == 0 && isYeJi){
					//只处理机器人,正负都处理
					UserRedisInfo.addYeJiFanXian(m_pIUserItem[i].dwUserID,Math.abs(vecRoundScore[i]),m_clubOwnerId);
				}
			}
			cmd.lShuiShou = realshui;
			for (int i = 0; i < 5; i++) {
				if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
					continue;
				}
				cmd.lUserCoin[i] = m_pIUserItem[i].lUserRmb;
			}
			
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			for (int i = 0; i < 5; i++) {// ����ƾ�����
				m_byQiangZhuang[i] = 0;
				m_byXiaZhu[i] = 0;
				m_byXuanNiu[i] = 0;
				m_vecRoundScore[i] = 0;
			}
			m_wZhuangPower = 1;
			m_byZhuang = 0;
		}

		if (m_byRound <= 1 && cbReason == Constants.GAME_END_DISMISS) {
			SUBCMD_S_DismissRoom cmd = new SUBCMD_S_DismissRoom();
			cmd.lUid = 0;
			cmd.cbResult = 0;
			cmd.m_wUserChairID = 0;
			cmd.m_dwTableID = m_dwTableID;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			DelayRemove();
			beforeDestroy(cloneServerUserPack(m_pIUserItem),null,m_doubleVecResultScore);
			QpGameMgr.getInstance().OnDismissRoom(this);

		} else if (m_byRound > m_byMaxRound || cbReason == Constants.GAME_END_DISMISS) {
			if(m_byRound > m_byMaxRound){
				for(int i = 0;i < 5;i++){
					if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
						continue;
					}
					SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
					if(user != null){
						user.getDwcJuShu(1);
					}
				}
			}
			SUBCMD_S_REPORT cmd = new SUBCMD_S_REPORT();
			cmd.cbReason = cbReason;
			cmd.whoDismiss = 0;

			for (int k = 0; k < 5; k++) {
				cmd.vecWinScore[k] = m_vecWinScore[k];
				cmd.vecLoseScore[k] = m_vecLoseScore[k];
				cmd.vecResultScore[k] = m_doubleVecResultScore[k];
			}

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			DelayRemove();

			beforeDestroy(cloneServerUserPack(m_pIUserItem),null,m_doubleVecResultScore);
			QpGameMgr.getInstance().OnDismissRoom(this);
		}	
	}
	void onEventGameEndGold(int bySeatID, int cbReason) {
		if(cbReason != Constants.GAME_END_DISMISS){
			m_byRound = m_byRound + 1;
			OnRoundInfoChange();
		}
		m_curStage = "STAGE_JIESUAN";
		needDealTime = 6;

		m_bGameStarted = false;
		int cntUser = 0;
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].isAndroidUser == 0) {
				cntUser++;
			}
		}
		m_aiRobotDelay = (int) (4 + CommonDef.getRandomInt(3) + cntUser * 1);
		if (cbReason != Constants.GAME_END_DISMISS) {			
			double shuishourate = getShuiShou(this.GetType());
			int shui = (int) (this.m_difen * shuishourate);
			double[] realshui = new double[5];
			for(int i = 0;i < 5;i++){
				realshui[i] = 0;
			}
			//扣税
			SUBCMD_S_JieSuan cmd = new SUBCMD_S_JieSuan();
			for(int i = 0;i < 5;i++){
				if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
					continue;
				}
				if(i == m_byZhuang){
					//庄家都扣税
					realshui[i] = shui;
					SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
					//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
					m_pIUserItem[i].lUserCoin -= shui;
					user.getCoin(0 - shui);
					if(m_pIUserItem[i].isAndroidUser == 0){
						UserGoldChange.handleGoldChangeKouShui(user, shui, UserGoldChange.reason8);
						this.addEatNormalScore(shui);
						handleGoldGiveBack(m_pIUserItem[i].dwUserID,shui);
					}else{
						//机器人
						this.addEatRobotScore(shui);
					}
				}else if(m_vecCardType[i] > m_vecCardType[m_byZhuang]){
					//闲家赢了
					if(m_kouShuiMode.equals("lose")){
						continue;
					}
					realshui[i] = shui;
					SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
					//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
					m_pIUserItem[i].lUserCoin -= shui;
					user.getCoin(0 - shui);
					if(m_pIUserItem[i].isAndroidUser == 0){
						UserGoldChange.handleGoldChangeKouShui(user, shui, UserGoldChange.reason8);
						this.addEatNormalScore(shui);
						handleGoldGiveBack(m_pIUserItem[i].dwUserID,shui);
					}else{
						//机器人
						this.addEatRobotScore(shui);
					}
				}else if(m_vecCardType[i] <= m_vecCardType[m_byZhuang]){
					//闲家输了
					if(m_kouShuiMode.equals("win")){
						continue;
					}
					realshui[i] = shui;
					SecShmUser user = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
					//扣除税收先,在扣除UU逗的时候，最多扣完,不会扣成负数(系统不补贴)
					m_pIUserItem[i].lUserCoin -= shui;
					user.getCoin(0 - shui);
					if(m_pIUserItem[i].isAndroidUser == 0){
						UserGoldChange.handleGoldChangeKouShui(user, shui, UserGoldChange.reason8);
						this.addEatNormalScore(shui);
						handleGoldGiveBack(m_pIUserItem[i].dwUserID,shui);
					}else{
						//机器人
						this.addEatRobotScore(shui);
					}
				}
			}

			for (int i = 0; i < 5; i++) {
				if (m_pIUserItem[i].dwUserID > 0) {
					int byOutCardData[] = new int[5];
					m_vecCardType[i] = m_GameLogic.GetCardType(m_bTableCardArray[i], 3, byOutCardData);
	
					cmd.bCardType[i] = m_vecCardType[i];

					cmd.bCardData[i][0] = byOutCardData[0];
					cmd.bCardData[i][1] = byOutCardData[1];
				} else {
					int byOutCardData[] = new int[5];
					cmd.bCardType[i] = -1;
					cmd.bCardData[i][0] = byOutCardData[0];
					cmd.bCardData[i][1] = byOutCardData[1];
				}
			}
			//0-8===1��    9===2��    28==3��    11-88===3��    99==4��  20==5��  
			int byPowerRate[] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2 ,5};		

			//庄家
			SecShmUser zhuangUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[m_byZhuang].dwUserID);
			for (int i = 0; i < 5; i++) {
				if (m_pIUserItem[i].dwUserID <= 0) {
					continue;
				}
				SecShmUser xianUser = dthall.getInstance().getSecurityUserInfo(m_pIUserItem[i].dwUserID);
				if (i != m_byZhuang) {
					if (m_vecCardType[i] > m_vecCardType[m_byZhuang]) {
						//闲家赢了
						int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[i]] * m_wZhuangPower * m_difen;
						if(Math.abs(coin) > zhuangUser.getCoin(0)){
							//校验下coin的数量
							coin = zhuangUser.getCoin(0);
						}
						m_vecRoundScore[m_byZhuang] -= coin;
						m_vecRoundScore[i] += coin;

						m_vecResultScore[m_byZhuang] -= coin;
						m_vecResultScore[i] += coin;
						
						m_pIUserItem[i].lUserScore += coin;
						m_pIUserItem[m_byZhuang].lUserScore -= coin;
						
						m_vecLoseScore[m_byZhuang] += 1;
						m_vecWinScore[i] += 1;
						
						//记录
						m_pIUserItem[i].lUserCoin += coin;
						m_pIUserItem[m_byZhuang].lUserCoin -= coin;
						zhuangUser.getCoin(0 - coin);
						xianUser.getCoin(coin);
						UserGoldChange.handleGoldChangeWinLose(zhuangUser,coin, UserGoldChange.reason21);
						UserGoldChange.handleGoldChangeWinLose(xianUser,coin,UserGoldChange.reason21);
						if(m_pIUserItem[i].isAndroidUser == 2){
							//robot win & lost
							this.addRobotWinScore(coin);
						}
					} else if (m_vecCardType[i] <= m_vecCardType[m_byZhuang]) {
						//庄家赢了
						int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[m_byZhuang]] * m_wZhuangPower * m_difen;
						if(Math.abs(coin) > xianUser.getCoin(0)){
							coin = xianUser.getCoin(0);
						}
						m_vecRoundScore[m_byZhuang] += coin;
						m_vecRoundScore[i] -= coin;

						m_vecResultScore[m_byZhuang] += coin;
						m_vecResultScore[i] -= coin;

						m_pIUserItem[i].lUserScore -= coin;
						m_pIUserItem[m_byZhuang].lUserScore += coin;
						
						m_vecWinScore[m_byZhuang] += 1;
						m_vecLoseScore[i] += 1;
						
						//记录
						m_pIUserItem[i].lUserCoin -= coin;
						m_pIUserItem[m_byZhuang].lUserCoin += coin;
						zhuangUser.getCoin(coin);
						xianUser.getCoin(0 - coin);
						UserGoldChange.handleGoldChangeWinLose(zhuangUser,coin, UserGoldChange.reason21);
						UserGoldChange.handleGoldChangeWinLose(xianUser,coin,UserGoldChange.reason21);
						if(m_pIUserItem[i].isAndroidUser == 2){
							//robot win & lost
							this.addRobotWinScore(coin);
						}
					}
				} else {

				}
			}

			for (int i = 0; i < 5; i++) {
				cmd.nRoundScore[i] = m_vecRoundScore[i];
				cmd.nUserScore[i] = m_pIUserItem[i].lUserScore;
			}
			cmd.lShuiShou = realshui;
			for (int i = 0; i < 5; i++) {
				if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
					continue;
				}
				cmd.lUserCoin[i] = m_pIUserItem[i].lUserCoin;
			}
			
			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			for (int i = 0; i < 5; i++) {// ����ƾ�����
				m_byQiangZhuang[i] = 0;
				m_byXiaZhu[i] = 0;
				m_byXuanNiu[i] = 0;
				m_vecRoundScore[i] = 0;
			}
			m_wZhuangPower = 1;
			m_byZhuang = 0;
		}

		if (m_byRound <= 1 && cbReason == Constants.GAME_END_DISMISS) {
			SUBCMD_S_DismissRoom cmd = new SUBCMD_S_DismissRoom();
			cmd.lUid = 0;
			cmd.cbResult = 0;
			cmd.m_wUserChairID = 0;
			cmd.m_dwTableID = m_dwTableID;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			DelayRemove();
			beforeDestroy(cloneServerUserPack(m_pIUserItem),m_vecResultScore,null);
			QpGameMgr.getInstance().OnDismissRoom(this);

		} else if (m_byRound > m_byMaxRound || cbReason == Constants.GAME_END_DISMISS) {
			if(m_byRound > m_byMaxRound){
				for(int i = 0;i < 5;i++){
					if (m_pIUserItem[i].dwUserID <= 0 || Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus) {
						continue;
					}
					SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
					if(user != null){
						user.getGoldJuShu(1);
					}
				}
			}
			SUBCMD_S_REPORT cmd = new SUBCMD_S_REPORT();
			cmd.cbReason = cbReason;
			cmd.whoDismiss = 0;

			for (int k = 0; k < 5; k++) {
				cmd.vecWinScore[k] = m_vecWinScore[k];
				cmd.vecLoseScore[k] = m_vecLoseScore[k];
				cmd.vecResultScore[k] = m_vecResultScore[k];
			}

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			DelayRemove();

			beforeDestroy(cloneServerUserPack(m_pIUserItem),m_vecResultScore,null);
			QpGameMgr.getInstance().OnDismissRoom(this);
		}
	}
	void OnEventGameEndZuJu(int bySeatID, int cbReason) {
		if(cbReason != Constants.GAME_END_DISMISS){
			m_byRound = m_byRound + 1;
			OnRoundInfoChange();
		}
		m_curStage = "STAGE_JIESUAN";
		needDealTime = 6;

		m_bGameStarted = false;
		int cntUser = 0;
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].isAndroidUser == 0) {
				cntUser++;
			}
		}
		if (cbReason != Constants.GAME_END_DISMISS) {
			{
				SUBCMD_S_JieSuan cmd = new SUBCMD_S_JieSuan();

				for (int i = 0; i < 5; i++) {
					if (m_pIUserItem[i].dwUserID > 0) {
						int byOutCardData[] = new int[5];
						m_vecCardType[i] = m_GameLogic.GetCardType(m_bTableCardArray[i], 3, byOutCardData);
						// ����
						cmd.bCardType[i] = m_vecCardType[i];
						// ������
						cmd.bCardData[i][0] = byOutCardData[0];
						cmd.bCardData[i][1] = byOutCardData[1];
					} else {
						int byOutCardData[] = new int[5];
						cmd.bCardType[i] = -1;
						cmd.bCardData[i][0] = byOutCardData[0];
						cmd.bCardData[i][1] = byOutCardData[1];
					}
				}
				//0-8===1��    9===2��    28==3��    11-88===3��    99==4��  20==5��  
				int byPowerRate[] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2 ,5};		
				// m_vecRoundScore һ�ֵ���Ӯ
				// m_vecResultScore �����������о���Ӯ
				for (int i = 0; i < 5; i++) {
					if (m_pIUserItem[i].dwUserID <= 0) {
						continue;
					}
					if (i != m_byZhuang) {
						int Multiple = 0;
						if (m_vecCardType[i] > m_vecCardType[m_byZhuang]) {
							int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[i]] * m_wZhuangPower;

							m_vecRoundScore[m_byZhuang] -= coin;
							m_vecRoundScore[i] += coin;

							m_vecResultScore[m_byZhuang] -= coin;
							m_vecResultScore[i] += coin;
							
							m_pIUserItem[i].lUserScore += coin;
							m_pIUserItem[m_byZhuang].lUserScore -= coin;
							
							m_vecLoseScore[m_byZhuang] += 1;
							m_vecWinScore[i] += 1;
						} else if (m_vecCardType[i] <= m_vecCardType[m_byZhuang]) {
							int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[m_byZhuang]] * m_wZhuangPower;

							m_vecRoundScore[m_byZhuang] += coin;
							m_vecRoundScore[i] -= coin;

							m_vecResultScore[m_byZhuang] += coin;
							m_vecResultScore[i] -= coin;

							m_pIUserItem[i].lUserScore -= coin;
							m_pIUserItem[m_byZhuang].lUserScore += coin;
							
							m_vecWinScore[m_byZhuang] += 1;
							m_vecLoseScore[i] += 1;
						}
						
//						else {
//							if (m_GameLogic.CompareCard(m_bTableCardArray[m_byZhuang], 2, m_bTableCardArray[i], 2) == 1) {// Next �� ׯ��
//								int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[i]] * m_wZhuangPower;
//
//								m_vecRoundScore[m_byZhuang] -= coin;
//								m_vecRoundScore[i] += coin;
//
//								m_vecResultScore[m_byZhuang] -= coin;
//								m_vecResultScore[i] += coin;
//								m_pIUserItem[i].lUserScore += coin;
//								m_pIUserItem[m_byZhuang].lUserScore -= coin;
//							} else {
//								int coin = m_byXiaZhu[i] * byPowerRate[m_vecCardType[m_byZhuang]] * m_wZhuangPower;
//
//								m_vecRoundScore[m_byZhuang] += coin;
//								m_vecRoundScore[i] -= coin;
//
//								m_vecResultScore[m_byZhuang] += coin;
//								m_vecResultScore[i] -= coin;
//
//								m_pIUserItem[i].lUserScore -= coin;
//								m_pIUserItem[m_byZhuang].lUserScore += coin;
//							}
//						}
					} else {

					}
				}

				for (int i = 0; i < 5; i++) {
					cmd.nRoundScore[i] = m_vecRoundScore[i];
					cmd.nUserScore[i] = m_pIUserItem[i].lUserScore;
				}
				SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

				for (int i = 0; i < 5; i++) {// ����ƾ�����
					m_byQiangZhuang[i] = 0;
					m_byXiaZhu[i] = 0;
					m_byXuanNiu[i] = 0;
					m_vecRoundScore[i] = 0;
				}
				m_wZhuangPower = 1;
				m_byZhuang = 0;

			}
		}

		if (m_byRound <= 1 && cbReason == Constants.GAME_END_DISMISS) {
			SUBCMD_S_DismissRoom cmd = new SUBCMD_S_DismissRoom();
			cmd.lUid = 0;
			cmd.cbResult = 0;
			cmd.m_wUserChairID = 0;
			cmd.m_dwTableID = m_dwTableID;

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			DelayRemove();
			QpGameMgr.getInstance().OnDismissRoom(this);

		} else if (m_byRound > m_byMaxRound || cbReason == Constants.GAME_END_DISMISS) {
			if(m_byRound > m_byMaxRound){
				for(int i = 0;i < 5;i++){
					SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
					if(user != null){
						user.getZuJuJuShu(1);
					}
				}
			}
			int before_cost[] = new int[5];
			int after_cost[] = new int[5];

			int cost[] = new int[5];			
			for(int i=0;i<5;i++)
			{
				before_cost[i] = 0;
				cost[i] = 0;
				after_cost[i] = 0;
			}
			
			for (int i = 0; i < 5; i++) 
			{				
				if(m_pIUserItem[i].dwUserID > 0)
				{
					SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
					if(user != null)
					{
						before_cost[i] = user.getGem(0);
					}
				}
			}			
			int minRound = 1;
			if (m_byRound > minRound) {

				if (m_payWay.equalsIgnoreCase("FZPAY")) {
					int cost_gem = 0;
					for (int i = 0; i < 5; i++) {
						if (m_pIUserItem[i].dwUserID > 0) {
							cost_gem += m_byCostGem;
						}
					}					
					if (m_Creator > 0) {
						SHMUser user = dthall.getInstance().getUserInfo(m_Creator);
						if (user != null) {
							user.getGem(0 - cost_gem);
						}
					} else {
						SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[0].dwUserID);
						if (user != null) {
							user.getGem(0 - cost_gem);
						}
						cost[0] = 0 - cost_gem;
					}
				}
				if (m_payWay.equalsIgnoreCase("AAPAY")) {
					for (int i = 0; i < 5; i++) {
						if (m_pIUserItem[i].dwUserID > 0) {
							SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
							if (user != null) {
								user.getGem(0 - m_byCostGem);
								cost[i] = 0 - m_byCostGem;
							}
						}
					}
				}
				if (m_payWay.equalsIgnoreCase("WINPAY")) {
					int maxUser = 5;
					int activeUser = 0;
					for(int i = 0;i < maxUser;i++){
						if (m_pIUserItem[i].dwUserID > 0){
							activeUser++;
						}
					}
					int maxcost = m_byCostGem * activeUser;
					List<Integer> winuser = new ArrayList<Integer>();
					int max = -1;
					for (int i = 0; i < maxUser; i++) {
						if (m_vecResultScore[i] > max) {
							max = m_vecResultScore[i];
						}
					}
					for (int i = 0; i < maxUser; i++) {
						if (m_vecResultScore[i] == max) {
							winuser.add(i);
						}
					}
					float rate = m_byRound * 1.0f / m_byMaxRound;
					if(rate > 1.0) rate = 1.0f;
					rate *= maxcost;
					Float frate = new Float(rate);
					int cost_gem = frate.intValue();
					cost_gem /= winuser.size();

					for (int i = 0; i < maxUser; i++) {
						if (m_pIUserItem[i].dwUserID > 0 && winuser.indexOf(i) != -1) {
							SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
							if (user != null) {
								user.getGem(0 - cost_gem);
								cost[i] = 0 - cost_gem;
							}
						}
					}
				}
				if (m_payWay.equalsIgnoreCase("CLUBPAY")) {
					int cost_gem = 0;
					for (int i = 0; i < 5; i++) {
						if (m_pIUserItem[i].dwUserID > 0) {
							cost_gem += m_byCostGem;
						}
					}					

					DbInfoMgr.getInstance().costClubOwnerGem(this.m_clubOwnerId,cost_gem);
				}
				for (int i = 0; i < 5; i++) 
				{				
					if(m_pIUserItem[i].dwUserID > 0)
					{
						SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[i].dwUserID);
						if(user != null)
						{
							after_cost[i] = user.getGem(0);
						}
					}
				}					
			}
			SUBCMD_S_REPORT cmd = new SUBCMD_S_REPORT();
			cmd.cbReason = cbReason;
			cmd.whoDismiss = 0;

			for (int k = 0; k < 5; k++) {
				cmd.vecWinScore[k] = m_vecWinScore[k];
				cmd.vecLoseScore[k] = m_vecLoseScore[k];
				cmd.vecResultScore[k] = m_vecResultScore[k];
			}

			SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

			log_counter++;
			log_counter = log_counter % 100;
			Long t = System.currentTimeMillis() / 1000;
			Long battle_id = (t % 1000000) * 100 + log_counter;
			
			int difen = 10;
			if(m_betMode.equals("BETMODE0")){
				difen = 10;
			}else if(m_betMode.equals("BETMODE1")){
				difen = 20;
			}else if(m_betMode.equals("BETMODE2")){
				difen = 30;
			}

			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String created = df.format(new Date());
			{
				JSONObject root = new JSONObject();

				root.put("command", "save_battle_log");
				root.put("battle_id", battle_id);

				root.put("room_type", GetType());

				root.put("room_id", m_dwTableID);
				root.put("creator", GetCreator());
				
				root.put("jushu", m_byMaxRound);
				root.put("limitscore", 0);
				root.put("difen", difen);
				
				if (m_payWay == "WINPAY") {
					root.put("payway", 1);	
				}else if (m_payWay == "BIGWINPAY") {
					root.put("payway", 2);
				}else{
					root.put("payway", 0);
				}
				root.put("created", created);
				root.put("uid0", (int) m_pIUserItem[0].dwUserID);
				root.put("nickname0", m_pIUserItem[0].szNickName);
				root.put("score0", m_vecResultScore[0]);
				root.put("cost0", cost[0]);
				root.put("uid1", (int) m_pIUserItem[1].dwUserID);
				root.put("nickname1", m_pIUserItem[1].szNickName);
				root.put("score1", m_vecResultScore[1]);
				root.put("cost1", cost[1]);
				root.put("uid2", (int) m_pIUserItem[2].dwUserID);
				root.put("nickname2", m_pIUserItem[2].szNickName);
				root.put("score2", m_vecResultScore[2]);
				root.put("cost2", cost[2]);
				root.put("uid3", (int) m_pIUserItem[3].dwUserID);
				root.put("nickname3", m_pIUserItem[3].szNickName);
				root.put("score3", m_vecResultScore[3]);
				root.put("cost3", cost[3]);
				root.put("uid4", (int) m_pIUserItem[4].dwUserID);
				root.put("nickname4", m_pIUserItem[4].szNickName);
				root.put("score4", m_vecResultScore[4]);
				root.put("cost4", cost[4]);
				
				root.put("headurl0", dthall.getInstance().Handle_OnGetUserAvatar(m_pIUserItem[0].dwUserID));
				root.put("headurl1", dthall.getInstance().Handle_OnGetUserAvatar(m_pIUserItem[1].dwUserID));
				root.put("headurl2", dthall.getInstance().Handle_OnGetUserAvatar(m_pIUserItem[2].dwUserID));
				root.put("headurl3", dthall.getInstance().Handle_OnGetUserAvatar(m_pIUserItem[3].dwUserID));
				root.put("headurl4", dthall.getInstance().Handle_OnGetUserAvatar(m_pIUserItem[4].dwUserID));
				
				if(m_clubId != 0){
					//club
					root.put("clubid", m_clubId);
					root.put("wfdesc", m_wanFaStr);
					if(m_payWay == "CLUBPAY"){
						root.put("payway", 10);
					}
					ClubRedis.getInstance().addClubBattleLog(m_clubId,root.toString());
				}
				GameDB.getInstance().push_task(null, root);

				try
				{
					for(int i =0;i<5;i++)
					{
						if(m_pIUserItem[i].dwUserID > 0 && cost[i] != 0)
						{
							JSONObject root_cost = new JSONObject();
							root_cost.put("command", "save_charge_log");
							root_cost.put("created", created);
							root_cost.put("uid", (int) m_pIUserItem[i].dwUserID);
							root_cost.put("before_cost", (int) before_cost[i]);
							root_cost.put("after_cost", (int) after_cost[i]);
							root_cost.put("cost", (int) cost[i]);
							root_cost.put("reason", "�û�" + m_pIUserItem[0].dwUserID + "����   ���˸�" + m_byMaxRound + "�� " + m_payWay );
							root_cost.put("room_id", m_dwTableID);
							
							GameDB.getInstance().push_task(null, root_cost);
						}
					}	
				}catch(Exception e)
				{
					e.printStackTrace();
				}
			}

			m_bTableStarted = false;
			for (int i = 0; i < 5; i++) {// ����ƾ�����
				m_vecResultScore[i] = 0;
			}

			DelayRemove();

			QpGameMgr.getInstance().OnDismissRoom(this);

		}

	}

	static int log_counter = 0;


	void OnDealQiangZhuang() {

		m_curStage = "STAGE_QIANGZHUANG";
		needDealTime = 2;

		List<Integer> vecQiangZhuang = new ArrayList<>();
		List<Integer> vecTmpUser = new ArrayList<>();
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				if (m_byQiangZhuang[i] > 0) {
					vecQiangZhuang.add(i);
				}
				vecTmpUser.add(i);
			}
		}
		int byQiangZhuang[] = new int[5];
		SUBCMD_S_DingZhuang cmd = new SUBCMD_S_DingZhuang();
		cmd.lUid = 0;
		cmd.wChairID = 0;
		cmd.wPower = 0;
		if (vecQiangZhuang.size() > 0) {
			int byZhuang = vecQiangZhuang.get(Constants.rand() % vecQiangZhuang.size());
			if (m_byQiangZhuang[byZhuang] == 0) {
				m_byQiangZhuang[byZhuang] = 1;
			}
			cmd.lUid = m_pIUserItem[byZhuang].dwUserID;
			cmd.wChairID = byZhuang;
			cmd.wPower = m_byQiangZhuang[byZhuang];

			for (int i = 0; i < vecQiangZhuang.size(); i++) {
				byQiangZhuang[vecQiangZhuang.get(i)] = m_byQiangZhuang[vecQiangZhuang.get(i)];
			}
			m_byZhuang = byZhuang;
		} else {
			if (vecTmpUser.size() > 0) {
				int byZhuang = vecTmpUser.get(Constants.rand() % vecTmpUser.size());
				if (m_byQiangZhuang[byZhuang] == 0) {
					m_byQiangZhuang[byZhuang] = 1;
				}
				for (int i = 0; i < 5; i++) {
					if (m_pIUserItem[i].dwUserID > 0) {
					} else {
						m_byQiangZhuang[i] = 0;
					}
				}
				cmd.lUid = m_pIUserItem[byZhuang].dwUserID;
				cmd.wChairID = byZhuang;
				cmd.wPower = m_byQiangZhuang[byZhuang];

				for (int i = 0; i < vecTmpUser.size(); i++) {
					byQiangZhuang[vecTmpUser.get(i)] = m_byQiangZhuang[vecTmpUser.get(i)];
					if (byQiangZhuang[vecTmpUser.get(i)] < 0 || byQiangZhuang[vecTmpUser.get(i)] > 250) {
						byQiangZhuang[vecTmpUser.get(i)] = 1;
					}
				}
				m_byZhuang = byZhuang;
			} else {
				return;
			}

		}
		for (int i = 0; i < 5; i++) {
			cmd.byQiangZhuang[i] = byQiangZhuang[i];
		}
		m_wZhuangPower = m_byQiangZhuang[m_byZhuang];
		m_wZhuangPower = 1;
		for(int i = 0;i < 5;i++){
			if(m_pIUserItem[i].dwUserID <= 0 || m_pIUserItem[i].cbUserStatus == Constants.US_LOOKON){
				continue;
			}
			SendData(i, cmd.getJsonData());
		}
	}
	
	void QiangZhuang(int byZhuang)
	{
		m_curStage = "STAGE_QIANGZHUANG";
		needDealTime = 5;
		m_aiRobotDelay = CommonDef.getRandomInt(3);
		
		SUBCMD_S_DingZhuang cmd = new SUBCMD_S_DingZhuang();
		cmd.lUid = 0;
		cmd.wChairID = 0;
		cmd.wPower = 0;
		
		if (m_byQiangZhuang[byZhuang] == 0) {
			m_byQiangZhuang[byZhuang] = 1;
		}
		cmd.lUid = m_pIUserItem[byZhuang].dwUserID;
		cmd.wChairID = byZhuang;
		cmd.wPower = m_byQiangZhuang[byZhuang];

		m_byZhuang = byZhuang;		

		cmd.byQiangZhuang[byZhuang] = 1;
		
		m_wZhuangPower = 1;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());		
	}

	void OnDealXiaZhu() {
		m_curStage = "STAGE_XIAZHU";
		needDealTime = 0;

		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && m_byZhuang != i && m_pIUserItem[i].cbUserStatus == Constants.US_PLAY) {
				if (m_byXiaZhu[i] == 0) {
//					m_byXiaZhu[i] = 1;

					SUBCMD_S_XiaZhu cmd = new SUBCMD_S_XiaZhu();
					cmd.lUid = m_pIUserItem[i].dwUserID;
					cmd.wChairID = i;
//					cmd.wPower = 1;
					
					if(i==m_byZhuang){
						cmd.wPower = 0;
					}else{
						if(m_betMode.equals("BETMODE0")){
							cmd.wPower = 1;
							m_byXiaZhu[i] = 1;
						}else if(m_betMode.equals("BETMODE1")){
							cmd.wPower = 5;
							m_byXiaZhu[i] = 5;
						}else{
							cmd.wPower = 10;
							m_byXiaZhu[i] = 10;
						}
					}
					
					SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
				}
			}
		}
	}
	
	int GetNextUser(int bySeatID)
	{
		int wNextUser = 0;
		for (int i = 1; i < 6; i++) {
			wNextUser = (bySeatID + i) % 5;
			if (m_pIUserItem[wNextUser].dwUserID > 0) {
				return wNextUser;
			}
			
		}
		return 0;
	}

	public static long currDealTime = 0;
	void OnDealAI(float dt) {
		m_DealTime = (int) (System.currentTimeMillis() / 1000);
		int cntUser = 0;
		for (int wChairID = 1; wChairID < 5; wChairID++) {
			if (m_pIUserItem[wChairID].dwUserID > 0) {
				cntUser++;
			}
		}
		if (m_curStage == "STAGE_FAPAI_1") {
			if(m_zhuangMode.equalsIgnoreCase("LUNZHUANG"))
			{
				m_byZhuang = m_nextUser;
				m_nextUser = GetNextUser(m_byZhuang);
				
				QiangZhuang(m_nextUser);
				
			}else if(m_zhuangMode.equalsIgnoreCase("DINGZHUANG"))
			{
				QiangZhuang(m_byZhuang);
			}else{
				OnDealQiangZhuang();
			}
			// needDealTime = 12;
		} else if (m_curStage == "STAGE_QIANGZHUANG") {
			OnDealXiaZhu();
		} else if (m_curStage == "STAGE_XIAZHU") {
			FaPai_2();			
			// needDealTime = 10;
		} else if (m_curStage == "STAGE_FAPAI_2") {
			OnEventGameEnd(0, Constants.GAME_END_NORMAL);
			needDealTime = (cntUser * 3 + 6) / 2;
		}
		
	}

	public  long currDealTime1 = 0;
	public  int m_aiRobotDelay = 0;
	public void OnDeal(int dt) {
		if(currDealTime1 == 0){
			currDealTime1 = System.currentTimeMillis();
		}else{
			long time = System.currentTimeMillis();
			if((time - currDealTime1) >= 1000){
				currDealTime1 = time;
			}else{
				return;
			}
		}
		if(this.isGoldType() || this.isDwcType()){
			addRobotUser();
			if(m_aiRobotDelay <= 0){
				OnDealRobot();//机器人操作
			}else{
				m_aiRobotDelay--;
			}
		}
		if (m_bTableStarted == true) {
			if (needDealTime > 0) {
				needDealTime--;
				return;
			}
			if (m_wFaPaiDelay > 0) {
				m_wFaPaiDelay--;
				return;
			}
			if (m_bGameStarted) {
				OnDealAI(dt);
			} else {
//				OnEventGameStart();
			}
		}else{
		}	
	}
	public boolean isQiangZhuang(int _uid){
		
		int bySeatID = FindSeat(_uid);	
		
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0&&m_pIUserItem[i].cbUserStatus == Constants.US_PLAY) {
				int byOutCardData[] = new int[5];
				m_vecCardType[i] = m_GameLogic.GetCardType(m_bTableCardArray[i], 5, byOutCardData);
			} 

		}
		int winNum = 0;
		int loseNum = 0;
		for(int i=0;i<5;i++){
			if(i != bySeatID&&m_pIUserItem[i].isAndroidUser==0&&m_pIUserItem[i].cbUserStatus == Constants.US_PLAY){
				if(m_vecCardType[bySeatID]>m_vecCardType[i]){
					winNum++;
				}else{
					loseNum++;
				}
			}
		}
		if(winNum>loseNum){
			return true;
		}else if(CommonDef.getRandomInt(100) > 90){
			//偶发的抢庄
			return true;
		}
		return false;
	}
	void OnDealRobot() {

		if (m_bTableStarted == true) {

			if (m_curStage == "STAGE_FAPAI_1") {
				if (m_zhuangMode.equalsIgnoreCase("QIANGZHUANG")) {
					for (int i = 0; i < 5; i++) {

						if (m_pIUserItem[i].dwUserID > 0
								&& m_pIUserItem[i].isAndroidUser == 2 && m_byQiangZhuang[i] == 0) {
							if(CommonDef.getRandomInt(100) > 20){
								//有几率不做操作
								continue;
							}
							if (isQiangZhuang(m_pIUserItem[i].dwUserID) == true) {
								String vecArg[] = {"" + m_pIUserItem[i].dwUserID, "qiangzhuang", "1" };
								Handle_onQiangZhuang(m_pIUserItem[i].dwUserID,
										vecArg);
							} else {
								String vecArg[] = {"" + m_pIUserItem[i].dwUserID,  "buqiangzhuang", "0" };
								Handle_onBuQiangZhuang(
										m_pIUserItem[i].dwUserID, vecArg);
							}
						}
					}
				}
			} else if (m_curStage == "STAGE_QIANGZHUANG") {
				for (int i = 0; i < 5; i++) {

					if (m_pIUserItem[i].dwUserID > 0
							&& m_pIUserItem[i].isAndroidUser == 2 && m_byXiaZhu[i] == 0) {
						if (m_byZhuang != i) {
							if(CommonDef.getRandomInt(100) > 20){
								//有几率不做操作
								continue;
							}
							int[] default_xiazhu = { 1, 2, 3 };

							if (m_betMode.equalsIgnoreCase("BETMODE0")) {
								int[] default_xiazhu1 = { 1, 2, 3 };
								Constants.CopyMemory(default_xiazhu,
										default_xiazhu1, 3);
							}
							if (m_betMode.equalsIgnoreCase("BETMODE1")) {
								int[] default_xiazhu2 = { 4, 5, 6 };
								Constants.CopyMemory(default_xiazhu,
										default_xiazhu2, 3);
							}
							if (m_betMode.equalsIgnoreCase("BETBIG")) {
								int[] default_xiazhu3 = { 8, 9, 10 };
								Constants.CopyMemory(default_xiazhu,
										default_xiazhu3, 3);
							}
							//倍数
							String power = "";
							if(CommonDef.getRandomInt(100) > 20)
								power = String.valueOf(default_xiazhu[0]);
							else if(CommonDef.getRandomInt(100) > 10)
								power = String.valueOf(default_xiazhu[1]);
							else
								power = String.valueOf(default_xiazhu[2]);
							String vecArg[] = { "xiazhu","" + m_byRound, power };
							Handle_onXiaZhu(m_pIUserItem[i].dwUserID,
									vecArg);
						}
					}
				}

			} else if (m_curStage == "STAGE_FAPAI_2") {

				for (int i = 0; i < 5; i++) {

					if (m_pIUserItem[i].dwUserID > 0
							&& m_pIUserItem[i].isAndroidUser == 2 && m_byXuanNiu[i] == 0) {
						if(CommonDef.getRandomInt(100) > 80){
							//有几率不做操作
							continue;
						}
						int byOutCardData[] = new int[5];
						int type = m_GameLogic.GetCardType(m_bTableCardArray[i], 5, byOutCardData);
						String pai = "";
						for(int k = 0;k < 5;k++){
							pai += byOutCardData[k];
							if(k < 4){
								pai += ",";
							}
						}
						if(type == 1){
							String vecArg[] = { "xuanniu", "0" ,pai};
							Handle_onXuanNiu(m_pIUserItem[i].dwUserID, vecArg);
						}else{
							String vecArg[] = { "xuanniu", "1" ,pai};
							Handle_onXuanNiu(m_pIUserItem[i].dwUserID, vecArg);
						}
					}
				}
			} else if (m_curStage == "STAGE_JIESUAN") {
				if(CommonDef.getRandomInt(100) < 60){
					for (int wChairID = 0; wChairID < 5; wChairID++) {
						if (m_pIUserItem[wChairID].isAndroidUser == 2) {
							if(this.isGoldType()){
								if(m_pIUserItem[wChairID].cbUserStatus != Constants.US_READY){
									if(m_pIUserItem[wChairID].lUserCoin < m_lichang){
										//做一个delay，更真实
										if(this.m_autoGameIapDelay > 0){
											this.m_autoGameIapDelay--;
											return;
										}else if(this.m_autoGameIapDelay == 0){
											this.m_autoGameIapDelay = 10;
										}
										int [] applylist = {18888 + 2188,18888 + 2188,28888 + 2188,28888 + 2188,188888 + 2188,288888 + 2188,m_lichang + 1888};
										int applynum = 0;
										while(applynum < m_lichang){
											applynum = applylist[(int) (Math.random() * applylist.length)];
										}
										int gold = GoldMgr.getInstance().applyRobotGold(applynum);
										if(gold == 0.0){
											boolean hasdissmisstry = false;
											for(int k = 0;k < 5;k++){
												if(k == wChairID){
													continue;
												}
												if(m_byAgreeDismiss[k] == 1){
													hasdissmisstry = true;
												}
											}
											if(!hasdissmisstry && m_byAgreeDismiss[wChairID] != 1){
												String vecArg[] = {"normaluser","" + m_pIUserItem[wChairID].dwUserID};
												Handle_onTryDismissRoom(m_pIUserItem[wChairID].dwUserID, vecArg);
											}
											return;
										}else{
											SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[wChairID].dwUserID);
											m_pIUserItem[wChairID].lUserCoin += gold;
											user.addApplyNum(gold);
											user.getCoin(gold);
											Handle_GameIap(m_pIUserItem[wChairID].dwUserID, new String[2]);
										}
									}else{
										if(CommonDef.getRandomInt(100) < 70){
											Handle_onReady(m_pIUserItem[wChairID].dwUserID, new String[2]);
										}
									}
								}
							}else if(this.isDwcType()){
								if(m_pIUserItem[wChairID].cbUserStatus != Constants.US_READY){
									if(m_pIUserItem[wChairID].lUserRmb < m_lichang){
										//做一个delay，更真实
										if(this.m_autoGameIapDelay > 0){
											this.m_autoGameIapDelay--;
											return;
										}else if(this.m_autoGameIapDelay == 0){
											this.m_autoGameIapDelay = 10;
										}
										double [] applylist = {49.0,49.0,49.0,199.0,100.0,499.0,1299.0,1000.0,2000.0,m_lichang + 99.0};
										double applynum = 0.0;
										while(applynum < m_doubleDiFen){
											applynum = applylist[(int) (Math.random() * applylist.length)];
										}
										double rmb = GoldMgr.getInstance().applyRobotRmb(applynum);
										if(rmb == 0.0){
											boolean hasdissmisstry = false;
											for(int k = 0;k < 5;k++){
												if(k == wChairID){
													continue;
												}
												if(m_byAgreeDismiss[k] == 1){
													hasdissmisstry = true;
												}
											}
											if(!hasdissmisstry && m_byAgreeDismiss[wChairID] != 1){
												String vecArg[] = {"normaluser","" + m_pIUserItem[wChairID].dwUserID};
												Handle_onTryDismissRoom(m_pIUserItem[wChairID].dwUserID, vecArg);
											}
											return;
										}else{
											SHMUser user = dthall.getInstance().getUserInfo(m_pIUserItem[wChairID].dwUserID);
											m_pIUserItem[wChairID].lUserRmb += rmb;
											user.addApplyNum(rmb);
											user.addRmb1v1Value(rmb);
											Handle_GameIap(m_pIUserItem[wChairID].dwUserID, new String[2]);
										}
									}else{
										if(CommonDef.getRandomInt(100) < 70){
											Handle_onReady(m_pIUserItem[wChairID].dwUserID, new String[2]);
										}
									}
								}
							}
						}
					}
				}
			}
		} else {

		}

	}
	static int randRobotIndex = 999;

	void AddRobot() {
		randRobotIndex++;
		int robot_uid = randRobotIndex % 9999 + 200000;

		Vector<Integer> vecEmpty = new Vector<>();
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID == 0) {
				vecEmpty.add(i);

			}
		}
		if (vecEmpty.size() > 0) {
			int rand = Constants.rand(0, 10000);
			int wChairID = vecEmpty.get(Constants.rand() % vecEmpty.size());

			int vecMaleFace[] = { 1, 3, 5, 7, 9 };
			int vecFemaleFace[] = { 2, 4, 6, 8, 10 };
			m_pIUserItem[wChairID].dwUserID = robot_uid;
			m_pIUserItem[wChairID].lUserScore = 1000;
			m_pIUserItem[wChairID].wChairID = wChairID;
			m_pIUserItem[wChairID].cbGender = rand % 2;
			if (m_pIUserItem[wChairID].cbGender == 1) {
				m_pIUserItem[wChairID].dwFaceID = vecMaleFace[rand % 5];
			} else {
				m_pIUserItem[wChairID].dwFaceID = vecFemaleFace[rand % 5];
			}
			m_pIUserItem[wChairID].cbUserStatus = Constants.US_NULL;
			m_pIUserItem[wChairID].isAndroidUser = 1;
			
			m_pIUserItem[wChairID].szNickName = "USER[" + wChairID + "]";

			{
				SUBCMD_S_Sit cmd = new SUBCMD_S_Sit();
				// memset(&cmd, 0, sizeof(cmd));

				cmd.m_lUid = robot_uid;
				cmd.m_wUserChairID = m_pIUserItem[wChairID].wChairID;
				cmd.m_lUserScore = m_pIUserItem[wChairID].lUserScore;
				cmd.m_iAvatar = m_pIUserItem[wChairID].dwFaceID;
				cmd.szNickName = m_pIUserItem[wChairID].szNickName;
				cmd.szIP = "";
				cmd.m_byRound = m_UserStatus;
				
				SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			}
			{
				m_pIUserItem[wChairID].cbUserStatus = Constants.US_READY;

				SUBCMD_S_Ready cmd = new SUBCMD_S_Ready();
				// memset(&cmd, 0, sizeof(cmd));
				cmd.m_lUid = robot_uid;
				cmd.m_wUserChairID = m_pIUserItem[wChairID].wChairID;
				
				cmd.m_dwTableID = m_dwTableID;
				cmd.m_byRound = m_UserStatus;

				SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
			}
			m_wRobotSeconds[wChairID] = 0;
		}
	}
	public void DoAddGoldRobotPlayer(){
		int userCnt = 0;
		for(int i = 0;i < 5;i++){
			if(m_pIUserItem[i].dwUserID > 0){
				userCnt++;
			}
		}
		if(userCnt == 5){
			setNeedRobot(false,0);
			return;
		}
		
		int robot_gold = (int) RobotMgr.getInstance().getRandRobotGold(m_ruchang,m_difen);
		int gold = GoldMgr.getInstance().applyRobotGold(robot_gold);
		if(gold == 0){
			//申请不到足够的金币
			setNeedRobot(false,0);
			return;
		}
		Robot robot = RobotMgr.getInstance().AllocRobot();
		int robot_uid = robot.uid;
		SHMUser user = dthall.getInstance().getUserInfo(robot_uid);
		if(user == null){
			setNeedRobot(false,0);
			return;
		}
		user.m_lTotalCoin = gold;
		user.setApplyNum(gold);

		ArrayList<Integer> vecEmpty = new ArrayList<>();
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID == 0) {
				vecEmpty.add(i);
			}
		}
		if (vecEmpty.size() > 0) {
			if(this.m_clubId != 0){
				GameAgent agent = new GameAgent(user);
				net.sf.json.JSONObject json = new net.sf.json.JSONObject();
				String data = "JoinRoom|" + this.m_clubId + "|" + this.m_dwTableID;
				json.put("data", data);
				ClubMgr.getInstance().m_clubHandler.HandleOn_ClubInfo(agent, json);
			}else{
				OnUserSit(robot_uid);
			}

			// 主动准备
			class GoldReadyTask extends TimerTask{
				@Override
				public void run() {
					Handle_onReady(robot_uid, new String[2]);					
				}				
			}
			Timer timer = new Timer();
			timer.schedule(new GoldReadyTask(),1000 * CommonDef.randInt(1, 4));
		}
	}
	public void DoAddRmbRobotPlayer(){
		int userCnt = 0;
		for(int i = 0;i < 5;i++){
			if(m_pIUserItem[i].dwUserID > 0){
				userCnt++;
			}
		}
		if(userCnt == 5){
			setNeedRobot(false,0);
			return;
		}
		
		double robot_rmb = RobotMgr.getInstance().getRandRobotGold(m_ruchang,m_doubleDiFen);
		robot_rmb += Math.random() * 2;
		BigDecimal b = new BigDecimal(robot_rmb);
		robot_rmb = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
		double rmb = GoldMgr.getInstance().applyRobotRmb(robot_rmb);
		if(rmb == 0){
			//申请不到足够rmb
			setNeedRobot(false,0);
			return;
		}
		Robot robot = RobotMgr.getInstance().AllocRobot();
		int robot_uid = robot.uid;
		SHMUser user = dthall.getInstance().getUserInfo(robot_uid);
		if(user == null){
			setNeedRobot(false,0);
			return;
		}
		user.setRMb1v1Value(rmb);
		user.setApplyNum(rmb);

		ArrayList<Integer> vecEmpty = new ArrayList<>();
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID == 0) {
				vecEmpty.add(i);
			}
		}
		if (vecEmpty.size() > 0) {
			if(this.m_clubId != 0){
				GameAgent agent = new GameAgent(user);
				net.sf.json.JSONObject json = new net.sf.json.JSONObject();
				String data = "JoinRoom|" + this.m_clubId + "|" + this.m_dwTableID;
				json.put("data", data);
				ClubMgr.getInstance().m_clubHandler.HandleOn_ClubInfo(agent, json);
			}else{
				OnUserSit(robot_uid);
			}

			// 主动准备
			class GoldReadyTask extends TimerTask{
				@Override
				public void run() {
					Handle_onReady(robot_uid, new String[2]);					
				}				
			}
			Timer timer = new Timer();
			timer.schedule(new GoldReadyTask(),1000 * CommonDef.randInt(1, 4));
		}
	}
	public void DoAddRobotPlayer(){
		if(m_roomType.equals("GOLD")){
			DoAddGoldRobotPlayer();
		}else if(m_roomType.equals("DWC")){
			DoAddRmbRobotPlayer();
		}
	}
	void Handle_onJoin(int _Uid, String vecArg[]) {
		int bySeatID = FindSeat(_Uid);
		if (bySeatID < 5) {
			m_pIUserItem[bySeatID].cbOnline = Constants.US_NULL;
		}

		SUBCMD_S_Join cmd = new SUBCMD_S_Join();

		String sData = cmd.getJsonData();
		SendData(_Uid, sData);
	}

	void Handle_onReady(int _Uid, String vecArg[]) {
		if (m_bGameStarted == true) {
			return;
		}
		int bySeatID = FindSeat(_Uid);
		if (bySeatID < 5) {
			m_pIUserItem[bySeatID].cbUserStatus = Constants.US_READY;
			m_UserStatus[bySeatID] = Constants.US_READY;
		}
		int roomUserNumber = 0;
		UserCntReady = 0;
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].cbUserStatus == Constants.US_READY) {
				UserCntReady++;
			}
			if(m_pIUserItem[i].dwUserID > 0){
				roomUserNumber++;
			}
		}
		
		SUBCMD_S_Ready cmd = new SUBCMD_S_Ready();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = bySeatID;
		cmd.m_dwTableID = m_dwTableID;
		cmd.m_byRound = m_UserStatus;
		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		
		if(UserCntReady==roomUserNumber){
			OnEventGameStart();
		}
	}

	void Handle_onRobot(int _Uid, String vecArg[]) {
		if (m_bGameStarted == true) {
			return;
		}
		int bySeatID = FindSeat(_Uid);
		if (bySeatID < 5) {
			m_pIUserItem[bySeatID].cbUserStatus = Constants.US_READY;
		}
		int cntPlayer = 0;
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0) {
				cntPlayer++;
			}
		}
		if (cntPlayer < 5) {
			for (int i = 0; i < 5 - cntPlayer; i++) {
				AddRobot();
			}
		}
	}

	// ����
	void Handle_onBiaoQing(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, wChairID);
			return;
		}
		if (vecArg.length < 2)
			return;
		int index = Constants.atoi(vecArg[1]);

		SUBCMD_S_BiaoQing cmd = new SUBCMD_S_BiaoQing();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.m_iBiaoQingIndex = index;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		if((this.isGoldType() || this.isDwcType()) && m_pIUserItem[wChairID].isAndroidUser == 0){
			for(int i = 0;i < 5;i++){
				if(m_pIUserItem[i].isAndroidUser == 2){
					if(CommonDef.getRandomInt(100) < 30){
						class SendBiaoQingTask extends TimerTask{
							int index = 0;
							int seat = 0;
							int uid = 0;
							@Override
							public void run() {
								// TODO Auto-generated method stub
								SUBCMD_S_BiaoQing cmd = new SUBCMD_S_BiaoQing();
								cmd.m_lUid = uid;
								cmd.m_wUserChairID = seat;
								cmd.m_iBiaoQingIndex = index;
								SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
							}
						}
						Timer timer = new Timer();
						SendBiaoQingTask task = new SendBiaoQingTask();
						task.index = 1 + CommonDef.getRandomInt(11);
						task.seat = i;
						task.uid = m_pIUserItem[i].dwUserID;
						timer.schedule(task,1000 + CommonDef.getRandomInt(4000));
						return;
					}
				}
			}
		}
	}

	// ����
	void Handle_onYuYin(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, wChairID);
			return;
		}
		if (vecArg.length < 2)
			return;
		int index = Constants.atoi(vecArg[1]);

		SUBCMD_S_YuYin cmd = new SUBCMD_S_YuYin();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.m_iYuYinIndex = index;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		if((this.isGoldType() || this.isDwcType()) && m_pIUserItem[wChairID].isAndroidUser == 0){
			for(int i = 0;i < 5;i++){
				if(m_pIUserItem[i].isAndroidUser == 2){
					if(CommonDef.getRandomInt(100) < 30){
						class SendBiaoQingTask extends TimerTask{
							int index = 0;
							int seat = 0;
							int uid = 0;
							@Override
							public void run() {
								// TODO Auto-generated method stub
								SUBCMD_S_YuYin cmd = new SUBCMD_S_YuYin();
								cmd.m_lUid = uid;
								cmd.m_wUserChairID = seat;
								cmd.m_iYuYinIndex = index;
								SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
							}
						}
						Timer timer = new Timer();
						SendBiaoQingTask task = new SendBiaoQingTask();
						task.index = 0 + CommonDef.getRandomInt(5);
						task.seat = i;
						task.uid = m_pIUserItem[i].dwUserID;
						timer.schedule(task,1000 + CommonDef.getRandomInt(4000));
						return;
					}
				}
			}
		}
	}

	// ����
	void Handle_onSongLi(int _Uid, String vecArg[]) {
	}

	// ����
	void Handle_onChat(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, wChairID);
			return;
		}
		if (vecArg.length < 2)
			return;
		String strContent = vecArg[1];

		SUBCMD_S_Chat cmd = new SUBCMD_S_Chat();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.szContent = strContent;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
	}

	// ����
	void Handle_onVoice(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, wChairID);
			return;
		}
		if (vecArg.length < 3)
			return;
		int seconds = Constants.atoi(vecArg[1]);
		String strVoiceURL = vecArg[2];

		SUBCMD_S_Voice cmd = new SUBCMD_S_Voice();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.seconds = seconds;
		cmd.szVoiceURL = strVoiceURL;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
	}
	void Handle_onExpr(int _Uid, String[] vecArg) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		int uid1 = Integer.parseInt(vecArg[1]);
		int uid2 = Integer.parseInt(vecArg[2]);
		int index = Integer.parseInt(vecArg[3]);
		
		SUBCMD_S_ExprMsg cmd = new SUBCMD_S_ExprMsg();
		cmd.m_uid1 = uid1;
		cmd.m_uid2 = uid2;
		cmd.m_index = index;
		
		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
	}
	void Handle_onVoiceMsg(int _Uid, String[] vecArg) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		float seconds = Float.parseFloat(vecArg[1]);
		
		SUBCMD_S_VoiceMsg cmd = new SUBCMD_S_VoiceMsg();
		cmd.m_lUid = _Uid;
		cmd.m_wUserChairID = wChairID;
		cmd.seconds = seconds;
		
		cmd.data = vecArg[2];
		cmd.m_maxClip = Integer.parseInt(vecArg[3]);
		cmd.m_currClip = Integer.parseInt(vecArg[4]);
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
	}
	void Handle_onTryDismissRoom(int _Uid, String vecArg[]) {
		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			return;
		}
		if (vecArg.length < 2)
			return;
		String attachInfo = vecArg[1];
		if(attachInfo.equals("fzquit")){
			//房主请求直接退出
			OnEventGameEnd(0, Constants.GAME_END_DISMISS);
			return;
		}
		int cntUser = 0;
		int cntOnline = 0;
		int cntOffline = 0;
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && (m_pIUserItem[i].isAndroidUser == 0 || m_pIUserItem[i].isAndroidUser == 2)) {
				cntUser++;
			}
		}
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && (m_pIUserItem[i].isAndroidUser == 0 || m_pIUserItem[i].isAndroidUser == 2)) {
				if (m_pIUserItem[i].cbOnline == Constants.US_OFFLINE) {
					cntOffline++;
				} else {
					cntOnline++;
				}
			}
		}
		if (cntUser > 1) {
			if (m_dismissTimer == 0) {
				m_dismissTimer = Constants.time(null);
			}
			m_byAgreeDismiss[bySeatID] = 1;
			
			int cntAgree = 0;

			for (int i = 0; i < 5; i++) {
				if (m_byAgreeDismiss[i] > 0 || (m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON == m_pIUserItem[i].cbUserStatus)) {
					cntAgree++;
				}
			}
			
			if (cntAgree >= 2 && cntAgree >= cntUser - 1) {
				OnEventGameEnd(0, Constants.GAME_END_DISMISS);
			}else{
				SUBCMD_S_TryDismissRoom cmd = new SUBCMD_S_TryDismissRoom();
				cmd.lUid = _Uid;
				cmd.dwTableID = m_dwTableID;
				cmd.szNickName = m_pIUserItem[bySeatID].szNickName;
				
				for(int i = 0; i < 5; i ++)
				{	// 旁观者不参与解散房间
					if(m_pIUserItem[i].dwUserID > 0 && Constants.US_LOOKON != m_pIUserItem[i].cbUserStatus)
					{
						SendData(m_pIUserItem[i].dwUserID, cmd.getJsonData());
					}
				}
				
			
				if (cntOnline == 1) {
					OnEventGameEnd(0, Constants.GAME_END_DISMISS);
					m_dismissTimer = 0;
				}else{
					//处理robot，同意
					boolean hasRobot = false;
					for(int i = 0;i < 5;i++){
						if( m_pIUserItem[i].isAndroidUser == 2){
							hasRobot = true;
							break;
						}
					}
					if(hasRobot){
						try{
							class AgreeTask extends TimerTask{
			
								@Override
								public void run() {
									for(int i = 0;i < 5;i++){
										if( m_pIUserItem[i].isAndroidUser == 2){
											if(m_isDestoryed == false && m_byAgreeDismiss[i] == 0 && CommonDef.getRandomInt(100) > 50){
												String vecArg[] = {"agree_dismissroom","" + m_pIUserItem[i].dwUserID};
												Handle_onAgreeDismissRoom(m_pIUserItem[i].dwUserID,vecArg);
												return;
											}
										}
									}
								}					
							}
							Timer timer = new Timer();
							AgreeTask task = new AgreeTask();
							timer.schedule(task, 2000,2000);
						}catch(Exception e){
							
						}
					}
				}
			}
			
		} else {
			OnEventGameEnd(0, Constants.GAME_END_DISMISS);
		}
	}
	void Handle_onAgreeDismissRoom(int _Uid, String vecArg[]) {
		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, bySeatID);
			return;
		}
		if (vecArg.length < 2)
			return;
		m_byAgreeDismiss[bySeatID] = 1;

		SUBCMD_S_AgreeDismissRoom cmd = new SUBCMD_S_AgreeDismissRoom();
		cmd.lUid = _Uid;
		cmd.dwTableID = m_dwTableID;
		cmd.szNickName = m_pIUserItem[bySeatID].szNickName;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

		if (bySeatID == 0 && m_bTableStarted == false) {
			OnEventGameEnd(0, Constants.GAME_END_DISMISS);
			return;
		}
		int cntAgree = 0;
		for (int i = 0; i < 5; i++) {
			if (m_byAgreeDismiss[i] > 0) {
				cntAgree++;
			}
		}
		int cntUser = 0;
		for (int i = 0; i < 5; i++) {
			if (m_pIUserItem[i].dwUserID > 0 && (m_pIUserItem[i].isAndroidUser == 0 || m_pIUserItem[i].isAndroidUser == 2) && m_pIUserItem[i].cbOnline == 0) {
				cntUser++;
			}
		}
		if (cntAgree >= cntUser - 1) {
			OnEventGameEnd(0, Constants.GAME_END_DISMISS);
		}
	}

	// ����
	void Handle_onRefuseDismissRoom(int _Uid, String vecArg[]) {
		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, bySeatID);
			return;
		}
		if (vecArg.length < 2)
			return;

		m_dismissTimer = 0;
		m_byAgreeDismiss[0] = 0;
		m_byAgreeDismiss[1] = 0;
		m_byAgreeDismiss[2] = 0;
		m_byAgreeDismiss[3] = 0;
		m_byAgreeDismiss[4] = 0;

		SUBCMD_S_RefuseDismissRoom cmd = new SUBCMD_S_RefuseDismissRoom();
		cmd.lUid = _Uid;
		cmd.dwTableID = m_dwTableID;
		cmd.szNickName = m_pIUserItem[bySeatID].szNickName;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
	}

	void Handle_onStart(int _Uid, String vecArg[]) {
		if (vecArg.length < 2)
			return;

		int bySeatID = FindSeat(_Uid);
		if (m_bTableStarted == false && bySeatID == 0 && GetPlayerCount() > 1) {
			OnEventGameStart();
		}
	}

	void Handle_onQiangZhuang(int _Uid, String vecArg[]) {
		if (vecArg.length < 3)
			return;

		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, bySeatID);
			return;
		}

		m_byQiangZhuang[bySeatID] = 1;

		int power = Constants.atoi(vecArg[2]);

		SUBCMD_S_QiangZhuang cmd = new SUBCMD_S_QiangZhuang();
		cmd.lUid = _Uid;
		cmd.wChairID = bySeatID;
		cmd.wPower = power;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());

		int curNum = 0;
		int XuanZhuangN = 0;
		for (int i = 0; i < 5; i++) {
			if (m_byQiangZhuang[i] == 1 || m_byQiangZhuang[i] == -1) {
				XuanZhuangN++;
			}
			if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus == Constants.US_PLAY) {
				curNum++;
			}
		}
		if (XuanZhuangN >= curNum && m_curStage == "STAGE_FAPAI_1") {
			OnDealQiangZhuang();
		}
	}

	void Handle_onBuQiangZhuang(int _Uid, String vecArg[]) {
		if (vecArg.length < 3)
			return;
		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, bySeatID);
			return;
		}
		m_byQiangZhuang[bySeatID] = -1;
		SUBCMD_S_BuQiangZhuang cmd = new SUBCMD_S_BuQiangZhuang();
		cmd.lUid = _Uid;
		cmd.wChairID = bySeatID;

		SendData(Constants.INVALID_CHAIR, cmd.getJsonData());
		int curNum = 0;
		int XuanZhuangN = 0;
		for (int i = 0; i < 5; i++) {
			if (m_byQiangZhuang[i] == 1 || m_byQiangZhuang[i] == -1) {
				XuanZhuangN++;
			}
			if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus == Constants.US_PLAY) {
				curNum++;
			}
		}
		if (XuanZhuangN >= curNum && m_curStage == "STAGE_FAPAI_1") {
			needDealTime = 5;
			OnDealQiangZhuang();
		}

	}

	void Handle_onXiaZhu(int _Uid, String vecArg[]) {
		if (vecArg.length < 3)
			return;
		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			// printf("Handle_onXiaZhu Error _Uid(%d)(%d)\n", _Uid, bySeatID);
			return;
		}
		int nRound = Constants.atoi(vecArg[1]);
		int power = Constants.atoi(vecArg[2]);
		if (m_byXiaZhu[bySeatID] == 0) {
			m_byXiaZhu[bySeatID] = power;

			SUBCMD_S_XiaZhu cmd = new SUBCMD_S_XiaZhu();
			cmd.lUid = _Uid;
			cmd.wChairID = bySeatID;
			if(bySeatID==m_byZhuang){
				cmd.wPower = 0;
			}else{
				cmd.wPower = power;
			}
			for(int i = 0;i < 5;i++){
				if(m_pIUserItem[i].dwUserID <= 0 || m_pIUserItem[i].cbUserStatus == Constants.US_LOOKON)
					continue;
				SendData(i, cmd.getJsonData());
			}
			int curNum = 0;
			int xiazhuN = 0;
			for (int i = 0; i < 5; i++) {
				if (m_byXiaZhu[i] > 0) {
					xiazhuN++;
				}
				if (m_pIUserItem[i].dwUserID > 0 && m_pIUserItem[i].cbUserStatus == Constants.US_PLAY) {
					curNum++;
				}
			}
			if (xiazhuN >= curNum - 1 && m_curStage == "STAGE_QIANGZHUANG") {
				needDealTime = 12;
				OnDealXiaZhu();
				FaPai_2();
			}
		}
	}

	void Handle_onXuanNiu(int _Uid, String vecArg[]) {
		if (vecArg.length < 3)
			return;
		int bySeatID = FindSeat(_Uid);
		if (bySeatID == Constants.INVALID_CHAIR) {
			// printf("Handle_onBiaoQing Error _Uid(%d)(%d)\n", _Uid, bySeatID);
			return;
		}
		m_byXuanNiu[bySeatID] = 1;

		int curNum = 0;
		int xuanNiuN = 0;
		for (int i = 0; i < 5; i++) {
			if (m_byXuanNiu[i] > 0) {
				xuanNiuN++;
			}
			if (m_pIUserItem[i].dwUserID > 0) {
				curNum++;
			}
		}
		if (xuanNiuN >= curNum && m_curStage == "STAGE_FAPAI_2") {
			// ȫ��׼���÷��ڶ�����
			OnEventGameEnd(0, Constants.GAME_END_NORMAL);
			int cntUser = 0;
			for (int wChairID = 1; wChairID < 5; wChairID++) {
				if (m_pIUserItem[wChairID].dwUserID > 0) {
					cntUser++;
				}
			}
			needDealTime = (cntUser * 3 + 8) / 2;
		}
	}

	public int FindSeat(int _Uid) {
		for (int bySeatID = 0; bySeatID < 5; bySeatID++) {
			if (m_pIUserItem[bySeatID].dwUserID == _Uid) {
				return bySeatID;
			}
		}
		return Constants.INVALID_CHAIR;
	}

	public int m_DealTime = 0;

	public int getDealTime() {
		return m_DealTime;
	}
	
	public boolean m_bRemove = false;

	public void DelayRemove() {
		m_bRemove = true;
	}

	public void ResetKillFlag() {
		m_bRemove = false;
	}

	public boolean ShouldBeRemoved() {
		return m_bRemove;
	}
	
	public void Handle_onLock(Integer lUid, String[] vecArg) {
		
		if (vecArg.length < 2)
			return;
		if ( m_bTableStarted && m_pIUserItem[0].dwUserID == lUid) {//�Ѿ���ʼ �����Ƿ���
			int index = Constants.atoi(vecArg[1]);
			m_locked = index;			
			
		}
	}
	void Handle_InBack(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
				
		SUBCMD_S_InBack cmd = new SUBCMD_S_InBack();
		cmd.byActionUser = wChairID;
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
	}

	void Handle_InFore(int _Uid, String vecArg[]) {
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		
		SUBCMD_S_InFore cmd = new SUBCMD_S_InFore();
		cmd.byActionUser = wChairID;
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
	}
	void Handle_GameIap(int _Uid,String vecArg[]){
		int wChairID = FindSeat(_Uid);
		if (wChairID == Constants.INVALID_CHAIR) {
			return;
		}
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if(user == null){
			return;
		}
		SUBCMD_S_GameIap cmd = new SUBCMD_S_GameIap();
		cmd.uid = _Uid;
		cmd.seat = wChairID;
		if(this.isDwcType()){
			cmd.coin = user.getRmb1v1Value();
			m_pIUserItem[wChairID].lUserRmb = cmd.coin;
		}else{
			cmd.coin = user.getCoin(0);
			m_pIUserItem[wChairID].lUserCoin = (int) cmd.coin;
		}
		SendData(Constants.INVALID_CHAIR,cmd.getJsonData());
	}
	@Override
	public String getRoomInfo() {
		// TODO �Զ����ɵķ������
		//m_lStartTime
		//m_pIUserItem
		// m_bTableStarted;
		// m_byRound;
		// m_byMaxRound;
		//m_dwTableID
		String roomInfo = String.format("%s|%s|%s|%s|%s", 
				m_pIUserItem[0].GetUserInfo(), //#
				m_pIUserItem[1].GetUserInfo(), 
				m_pIUserItem[2].GetUserInfo(), 
				m_pIUserItem[3].GetUserInfo(),
				m_pIUserItem[4].GetUserInfo()
				);
		String descInfo = String.format("房间类型：二八杠  %d/%d局",m_byRound,m_byMaxRound);
		roomInfo = String.format("%s|%d|%d|%s", roomInfo,m_dwTableID,m_lStartTime,descInfo);
		
		return roomInfo;
	}
	
	public boolean isM_bGameStarted(){
		return m_bGameStarted;
	}
	
	@Override
	public int getPlayerCount() {
		// TODO Auto-generated method stub
		return GetPlayerCount();
	}
	@Override
	public int getCostGem() {
		// TODO Auto-generated method stub
		return m_byCostGem;
	}
	@Override
	public int getStatus() {
		// TODO Auto-generated method stub
		if(m_bTableStarted == false)
		{
			return 0;
		}
		return 1;
	}

	@Override
	public String getRoomDesc() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getCellScore() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getMinScore() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getPayway() {
		return m_payWay;
	}

	@Override
	public String GetRoundInfo() {
		return "" + m_byRound + "/" +  m_byMaxRound;
	}
}
